How to apply substring to every letter in array? [closed]

phone, as it stands, contains a jQuery object, which is an Array-like Object of DOM elements. If you want to iterate over all of them and get their inner text, applying .substring(8) to each, and building an array out of them, you can use something like this:

var phoneArray = $(data).find(".tel a").map(function (i, el) {
    return $(el).text().substring(8);
}).get();

DEMO: http://jsfiddle.net/96HWv/

(in the demo, I had to emulate what data could be, although I’m guessing it is an HTML string in your real code)

Leave a Comment