Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
101
rated 0 times [  106] [ 5]  / answers: 1 / hits: 35452  / 10 Years ago, tue, november 4, 2014, 12:00:00

I have defined and populated an array called vertices. I am able to print the output to the JavaScript console as below:



[v 2.11733 0.0204144 1.0852, v 2.12303 0.0131256 1.08902, v 2.12307 0.0131326 1.10733 ...etc. ]


However I wish to remove the 'v' character from each element. I have tried using the .replace() function as below:



var x;
for(x = 0; x < 10; x++)
{
vertices[x].replace('v ', '');
}


Upon printing the array to the console after this code I see the same output as before, with the 'v's still present.



Could anyone tell me how to solve this?


More From » arrays

 Answers
6

Strings are immutable, so you just have to re-assign their value:



vertices[x] = vertices[x].replace('v ', '');

[#68914] Sunday, November 2, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
nellykaliae

Total Points: 119
Total Questions: 95
Total Answers: 103

Location: Pitcairn Islands
Member since Fri, Oct 15, 2021
3 Years ago
;