- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 Articles
- Remove '0','undefined' and empty values from an array in JavaScript
- Selects every element that are preceded by a element with CSS
- How to remove every Nth element from an array JavaScript?
- JavaScript How to get all 'name' values in a JSON array?
- Array of adjacent element's average - JavaScript
- I'm generating a list from an array. How can I know what element I'm clicking in JavaScript?
- If the element repeats, remove all its instances from array in JavaScript
- Trim off '?' from strings in JavaScript
- In JavaScript, what is meant by 'a function expression is always a constant value'?
- Remove element from array referencing spreaded array in JavaScript
- Remove all cancelled tasks from the timer's task queue in Java
- Why addEventListener to 'select' element does not work in JavaScript?
- How to check for 'undefined' or 'null' in a JavaScript array and display only non-null values?
- How to remove a MySQL collection named 'group'?
- what is the main difference between '=' and '==' operators in javascript?

Advertisements