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?

demo

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

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -