How can I differentiate if an array is a simple array?
f.e
let simpleArr = ["hi","1",3,"5","this is a string",29999]
or an array of objects
f.e
let objectArr = [
{el1: "hi", el2: "hi"},
{el1: "hi2", el2: "hi2"},
{el1: "hi3", el2: "hi3"},
{el1: "hi4", el2: "hi4"},
]
Is the below enough?
const isObject = (obj) => typeof obj === 'object' && obj !== null
isArray(objectArr) && objectArr.every(isObject)
falsewhen the array contains objects and other data, e.g.[{}, true, {}]. Is that expected?const isSimpleArray = arr => !arr.some(x => typeof x === 'object')[null]->false