JSFiddle - React, Tailwind, and code Playground
by Abdul Ahmad
JavaScript
const arr = {
data: [],
findIn: function(callback) {
for (let i = 0; i < this.data.length; i++) {
const val = this.data[i];
if (callback(val)) return val;
}
},
};
const test = arr;
test.data = [
{ id: 1, val: 'poo 1' },
{ id: 2, val: 'poo 2' },
{ id: 3, val: 'poo 3' },
];
res = test.findIn(function(item) {
return item.val === 'poo 3';
});
console.log(res);