
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
JavaScript Remove all '+' from array wherein every element is preceded by a + sign
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' ]
- Related Questions & Answers
- Remove '0','undefined' and empty values from an array in JavaScript
- How to remove every Nth element from an array JavaScript?
- JavaScript How to get all 'name' values in a JSON array?
- Selects every <ul> element that are preceded by a <p> element with CSS
- Array of adjacent element's average - JavaScript
- In JavaScript, what is meant by 'a function expression is always a constant value'?
- Trim off '?' from strings in JavaScript
- Explain what is meant by a 'Levitating Light Bulb'?
- Why is 'class' a reserved word in JavaScript?
- I'm generating a list from an array. How can I know what element I'm clicking in JavaScript?
- what is the main difference between '=' and '==' operators in javascript?
- What is 'delete' Operator in JavaScript?
- What is 'new' Operator in JavaScript?
- What is 'void' Operator in JavaScript?
- If the element repeats, remove all its instances from array in JavaScript
Advertisements