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