
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Remove All Plus from Array in JavaScript
Let’s say the following is our array with elements preceded by a + sign −
var studentNames = [ '+John Smith', '+David Miller', '+Carol Taylor', '+John Doe', '+Adam Smith' ];
To remove the + sign, the code is as follows −
Example
studentNames = [ '+John Smith', '+David Miller', '+Carol Taylor', '+John Doe', '+Adam Smith' ]; console.log("The actual array="); console.log(studentNames); studentNames = studentNames.map(function (value) { return value.replace('+', ''); }); console.log("After removing the + symbol, The result is="); console.log(studentNames);
To run the above program, you need to use the following command −
node fileName.js.
Here my file name is demo205.js.
Output
This will produce the following output −
PS C:\Users\Amit\javascript-code> node demo205.js The actual array= [ '+John Smith', '+David Miller', '+Carol Taylor', '+John Doe', '+Adam Smith' ] After removing the + symbol, The result is= [ 'John Smith', 'David Miller', 'Carol Taylor', 'John Doe', 'Adam Smith' ]
Advertisements