Answers for "check if array or object js"

13

Javascript is object array

var colors=["red","green","blue"];

if(Array.isArray(colors)){
    //colors is an array
}
Posted by: Guest on July-22-2019
2

javascript is object array

/* The Array.isArray() method indicates whether 
the passed value is an array. */

let example1 = [1, 2, 3];
console.log(Array.isArray(example1)); // → true

let example2 = {a: 1, b: 2,c: 3};
console.log(Array.isArray(example2)); // → false
Posted by: Guest on March-01-2022
2

check object in array javascript

var obj = {a: 5};
var array = [obj, "string", 5]; // Must be same object
array.indexOf(obj) !== -1 // True
Posted by: Guest on June-06-2020
1

javascript is array or object

const data = [1,2,3,4,5];const isArray = Object.prototype.toString.call(data) === '[object Array]';console.log(isArray); // trueconst data = {id: 1, name: “Josh”};const isArray = Object.prototype.toString.call(data) === '[object Array]';console.log(isArray); // false
Posted by: Guest on April-27-2021

Code answers related to "check if array or object js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language