Skip to content

Tag: arrays

Find last matching object in array of objects

I have an array of objects. I need to get the object type (“shape” in this example) of the last object, remove it, and then find the index of the previous object in the array that has the same type, e.g. “shape”. So, obviously the type in this example will be “round”. But I…

Javascript: .push is not a function

I am having a problem with my code: I get this error: As far as I understand, this is because it is treating the array argument as something other than an array. However, I thought I fed it the variable “current” which is an array. Can someone explain the problem? Thanks. Answer Array.push doesn&#…

How to convert an array of key-value tuples into an object

I have an array: But I can’t access data via an array’s key, e.g. arr[‘txnId’] does not return 20181. How can I convert the above array of tuples into an object, so that I can easily access data by key. Answer Update June 2020 ECMAScript 2021 brings Object.fromEntries which does exactl…