I need some help,
I've got a json with some parameters inside of it, actually 2 but one day we may add some more in it.
I want to find between some object in an array the right one thanks to all parameters in the json
Am i using the right method ?
to be clearer, i want the param.t
to match with the element.t
, and the param.tid
to match with the element.tid
and if moving forward one more parameter cd1
is added to the JSON, this param.cd1
will match with element.cd1
thanks for the time !
const array1 = [{"t":"pageview","de":"UTF-8","tid":"UA-xxxxxxxxxx-17","cd1":"Without cookie"},{"t":"timing","de":"UTF-8","tid":"UA-xxxxxxxx-1","cd1":"France"}];
const param = { t: 'pageview', tid: 'UA-xxxxxxxxxx-17' }
for (let [key, value] of Object.entries(param)) {
console.log(`${key}: ${value}`);
}
const obj = array1.find(element => element.t == param.t);
question from:
https://stackoverflow.com/questions/65844301/verify-and-select-the-right-object-in-an-array-thanks-to-a-find-method-which-wil 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…