JavaScript 从每个元素之前都有 + 号的数组中删除所有 +
假设我们的数组中每个元素前面都有一个 + 号,如下 −
var studentNames = [ '+John Smith', '+David Miller', '+Carol Taylor', '+John Doe', '+Adam Smith' ];
若要移除 + 号,代码如下 −
示例
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);要运行上述程序,你需要使用以下命令 −
node fileName.js.
我的文件名是 demo205.js。
输出
将产生以下输出 −
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' ]
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP