let names=['Jhon','David','Mark'];console.log(Array.isArray(names));// truelet user={id:1,name:'David'};console.log(Array.isArray(user));// falselet age 18;console.log(Array.isArray(age));// false
// how to check value is array or not in javascriptconst str ="foo";const check =Array.isArray(str);console.log(check);// Result: falseconst arr =[1,2,3,4];const output =Array.isArray(arr);console.log(output);// Result: true
let fruit ='apple';let fruits =["apple","banana","mango","orange","grapes"];constisArray=(arr)=>Array.isArray(arr);console.log(isArray.(fruit));//output - falseconsole.log(isArray.(fruits));//output- true
javascript - Determine whether an array contains a value
varcontains=function(needle){// Per spec, the way to identify NaN is that it is not equal to itselfvar findNaN = needle !== needle;var indexOf;if(!findNaN &&typeofArray.prototype.indexOf==='function'){
indexOf =Array.prototype.indexOf;}else{indexOf=function(needle){var i =-1, index =-1;for(i =0; i <this.length; i++){var item =this[i];if((findNaN && item !== item)|| item === needle){
index = i;break;}}return index;};}return indexOf.call(this, needle)>-1;};