NyansusCoder
NyansusCoder

Reputation: 89

JavaScript: TypeError: element.include is not a function

CLOSED. forgot s in includes :(.

Hello, I'm new in JavaScript so I have got stuck with an arrow function and .isInclude Array method. My array for experiments:

var yarr = [['age', [22, 23, 24, 26, 28]], 
            ['age', [11, 18, 24, 55, 88]],
            ['qwe', [11, 18, 24, 55, 88]]];

This code works good:

function  isIncludeValue(arrayOfArray, value){
    let accum = 0;
    for (let i = 0; i < arrayOfArray.length; i++) {
        accum =accum || (arrayOfArray[i].includes(value));
    }
    return accum;
}
 let e = isIncludeValue(yarr, 'qwe');
 console.log(e) //true

But this code give me TypeError:

function isIncludeTwo(arrayOfArray, value){
    let accum = 0;
    arrayOfArray.forEach(element =>  accum = accum || element.include(value))
    return accum;
}
let e = isIncludeTwo(yarr, 'qwe');
console.log(e)
//TypeError: element.include is not a function
//at arrayOfArray.forEach.element

And another thing in which I have doubt is storaging data in arrays, but the JS classes (sugared functions) seems to me too bulky for simple filtration task.

Upvotes: 0

Views: 4196

Answers (1)

Ghonima
Ghonima

Reputation: 3082

It should be includes not include

Upvotes: 3

Related Questions