javascript match first two letter in a string -
i have 1 string "united states united kingdom of britain and northern republic of ireland united nation" need match first 2 letter of every word.above string result 'un' 'st' 'un' 'ki' 'un' 'na'.
how can proceed help of javascript\jquery.
using array#map:
"united states united kingdom of britain and northern republic of ireland united nation".split(" ").map(function(element) {return element.substr(0,2)}) using regular expression:
"united states united kingdom of britain and northern republic of ireland united nation".match(/\b\w\w/g) javascript
No comments:
Post a Comment