समस्या
हमें एक JavaScript फ़ंक्शन लिखना है जो Array के प्रोटोटाइप ऑब्जेक्ट पर रहता है। यह एक लिटरल मान लेना चाहिए, और यदि वह मान उस ऐरे में मौजूद है जिस पर इसे कॉल किया जा रहा है तो true लौटाना चाहिए, अन्यथा false।
उदाहरण
निम्नलिखित कोड है −
const arr = [1, 2, 3, 4, 5, 6, 7, 8]; const num = 6; Array.prototype.customIncludes = function(num){ for(let i = 0; i < this.length; i++){ const el = this[i]; if(num === el){ return true; }; }; return false; }; console.log(arr.customIncludes(num));आउटपुट
true