javascript - Split string by hashtag and save into array with jQuery? -
i have var has string series of words, of have hashtags, eg:
var words = "#hashtagged no hashtag #antoherhashtag";
i want save each hashtagged word array, kind of like:
var tagslistarr = words.split(' ');
but unsure of how characters surrounded both # , space.
is there special way of doing this? there ascii characters meant use identify this?
var words = "#hashtagged no hashtag #antoherhashtag"; var tagslistarr = words.split(' '); var arr=[]; $.each(tagslistarr,function(i,val){ if(tagslistarr[i].indexof('#') == 0){ arr.push(tagslistarr[i]); } }); console.log(arr);
tagslistarr = words.split(' ')
splits words spaces new array
$.each() loops through each value of tagslistarr
array
if(tagslistarr[i].indexof('#') == 0)
checks #
in beginning of , if condition true
adds arr
array
Comments
Post a Comment