मान लीजिए निम्नलिखित समान वैल्यूज़ वाला हमारा ऐरे है -
const listOfStudentName = ['John', 'Mike', 'John', 'Bob','Mike','Sam','Bob','John'];
ऐरे से समान वैल्यूज़ हटाने के लिए, set() की अवधारणा का उपयोग करें। कोड निम्नलिखित है -
उदाहरण
const listOfStudentName = ['John', 'Mike', 'John', 'Bob','Mike','Sam','Bob','John'];
console.log("The value="+listOfStudentName);
const doesNotContainSameElementTwice = [...new Set(listOfStudentName)];
console.log("The Array=");
console.log(doesNotContainSameElementTwice)उपरोक्त प्रोग्राम चलाने के लिए, आपको निम्नलिखित कमांड का उपयोग करना होगा -
node fileName.js.
यहां, मेरा फ़ाइल नाम demo42.js है।
आउटपुट
यह निम्नलिखित आउटपुट देगा -
PS C:\Users\Amit\JavaScript-code> node demo42.js The value=John,Mike,John,Bob,Mike,Sam,Bob,John The Array= [ 'John', 'Mike', 'Bob', 'Sam' ]