다음이 요소 앞에 + 기호 −
가 있는 배열이라고 가정해 보겠습니다.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' ]