Answers for "what does an object array look like"

18

find an object in an array of objects javascript

let arr = [
    { name:"string 1", value:"this", other: "that" },
    { name:"string 2", value:"this", other: "that" }
];

let obj = arr.find(o => o.name === 'string 1');

console.log(obj);
Posted by: Guest on May-08-2020
0

javascript array-like object

function Arraylike(... args) {
    this.xarg = args;
    this.slice = function(num) {
        return new Arraylike(...this.xarg.slice(num));
    };
    this.splice = function(... args) {
        console.error("Splice is not implemented for now.");
    };
    this.toArray = function() {
        return this.xarg;
    };
    this.length = this.xarg.length;
    for(let i = 0; i < this.xarg.length; i++) {
        this[i] = this.xarg[i];
    }
}



Array.prototype.toArraylike = function() {
    return new Arraylike(...this);
};


let yourobject = new Arraylike("whatever", "goes", "here");
Posted by: Guest on April-29-2021

Code answers related to "what does an object array look like"

Code answers related to "Javascript"

Browse Popular Code Answers by Language