Remove first letter in string of every index in an array - Javascript

时间:2015-07-28 16:43:35

标签: javascript foreach

i have a a data model like this:

[#hello, #world, #foo, #bar]

I want to loop through each one of them and remove the number symbol, How di i go about his?

2 个答案:

答案 0 :(得分:4)

Loop over the Array with your favourite method (e.g. arr.map) and use str.slice(1)

['#hello', '#world', '#foo', '#bar'].map(function (e) {
    return e.slice(1);
}); // ["hello", "world", "foo", "bar"]

答案 1 :(得分:0)

you can loop through each string of the array and perform a operation.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr