Answer the question
In order to leave comments, you need to log in
How to select objects by the value of another object?
Good afternoon. I have an object:
obj = {
ticker: "SPY",
strategy: "LOG",
broker: ""
}
const a = {
ticker: 'SPY',
strategy: 'OLD',
broker: 'OOH'
};
const b = {
ticker: 'SPY',
strategy: 'LOG',
broker: 'FOR'
};
const c = {
ticker: 'HG',
strategy: 'KIP',
broker: 'LOOP'
};
Answer the question
In order to leave comments, you need to log in
const a = {
ticker: 'SPY',
strategy: 'OLD',
broker: 'OOH'
};
const b = {
ticker: 'SPY',
strategy: 'LOG',
broker: 'FOR'
};
const c = {
ticker: 'HG',
strategy: 'KIP',
broker: 'LOOP'
};
const obj = {
ticker: "SPY",
strategy: "LOG",
broker: ""
};
const objs = [a, b, c];
let out = [];
for (let i = 0; i < objs.length; i++) {
if (objs[i].ticker === obj.ticker && objs[i].strategy === obj.strategy) {
out.push(objs[i]);
}
}
console.log(out);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question