I wish I can create a function that will help me to get the last item from an array, NOT just from a normal array, but from other array types such as NodeList, (the only two types I know are NodeLists and Arrays)
my function:
const getLastItem = (list) => {
if (list instanceof Array || OR NODELIST OR ANYTHING ELSE) {
return list.slice(-1)[0];
}
if(typeof list == 'object'){
// get the last key from an object, it's another thing which I wish to append to this
// function
return Object.keys(list).slice(-1)[0]
//this will return the last key from an object
}
}
[EDIT]: and do you think that there is a better implementation than this one?
function isIterable(obj) { return typeof obj[Symbol.iterator] === 'function'; }[-1]syntax.