Hi all,
I’ve found a couple of articles that explain how to onvert an object to an array simply.
Both suggest something like this:
Object.entries(numbers);
// [ ['one', 1], ['two', 2] ]
and
var obj ={"1":5,"2":7,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0}
Object.entries(obj);
replacing ‘numbers/obj’ with my object.
However, whenever I try this, or other variations found online, I get an error:
"Parser Error: Formatter "entries" does not exist, expression {{object.entries(h)}}"
Wappler does have the keys and values formatters, which appear to be an older version of what was available for getting keys / values from an object and turning them into an array. What I’m trying to do is get the full key pair.
UPDATE:
Got a bit further by creating a custom formatter:
// JavaScript Document
exports.objecttoarray = function (obj) {
if (typeof obj != 'object') return obj;
return Object.entries(obj);
};
However, it’s returning key pairs for every item within the object, which isn’t ideal - if any JS experts might have any ideas, I’d be grateful!
Last updated: