score:2

Accepted answer
const
    array1 = [{ key1: 7, key2: 1, key3: 37 }],
    array2 = [{ title: 'Some Title 1', key: 'key1', number: '', icon: '../../assets/some2.png' }, { title: 'Some Title 2', key: 'key2', number: '', icon: '../../assets/some1.png' }, { title: 'Some Title 3', key: 'key3', number: '', icon:'../../assets/some3.png' }],
    result = array2.map(o => Object.assign({}, o, { number: array1[0][o.key] }));

console.log(result);

score:0

const array1 = [{
	key1: 7,
	key2: 1,
	key3: 37,
 }];

 const array2 = [
  {
      title: 'Some Title 1',
      key: 'key1',
      number: '',
      icon: '../../assets/some2.png'
  },
  {
      title: 'Some Title 2',
      key: 'key2',
      number: '',
      icon: '../../assets/some1.png'
  },
  {
      title: 'Some Title 3',
      key: 'key3',
      number: '',
      icon: '../../assets/some3.png'
  },
];

array2.forEach(e => e.number = array1[0][e.key]);
console.log(array2)

score:0

const array1 = [{
                key1: 7,
                key2: 1,
               }];
const array2 = [
  {
      title: 'Some Title 1',
      key: 'key1',
      number: '',
      icon: '../../assets/some2.png'
  },
  {
      title: 'Some Title 2',
      key: 'key2',
      number: '',
      icon: '../../assets/some1.png'
  },
  {
      title: 'Some Title 3',
      key: 'key3',
      number: '',
      icon: '../../assets/some3.png'
  },
];
const resultArray = array2.filter(item => array1[0][item.key]);

console.log(resultArray);

score:0

const keys = [
  {
    key1: 7,
    key2: 1,
    key3: 37,
  },
  {
    key4: 7,
    key5: 1,
    key6: 37,
  }
];

const array2 = [
  {
      title: 'Some Title 1',
      key: 'key4',
      number: ''
  },
  {
      title: 'Some Title 2',
      key: 'key2',
      number: ''
  },
  {
      title: 'Some Title 3',
      key: 'key3',
      number: ''
  }
];

function populateArrayData (arr, propToCompare, propToReplace, keysObj) {
  let populatedArray = [];
  
  if (Array.isArray(arr)) {
    populatedArray = arr.map((item) => {
      if (checkIfKeyExists(item[propToCompare], keysObj)) {
          item[propToReplace] = keysObj[item[propToCompare]];
      }
      return item;
    });
  }
  
  return populatedArray;
}

function flattenAllKeys (keys) {
  let flattenedKeysObj = {};
  
  if (Array.isArray(keys)) {
    flattenedKeysObj = keys.reduce((acc, keysObj) => {
      acc = {...acc, ...keysObj};
      return acc;
    }, {});
  }

  return flattenedKeysObj;
}

            
function checkIfKeyExists(key, keysObj) {
  return (keysObj[key]!== undefined && keysObj[key]!== null);
}
  
let flattenedKeys = flattenAllKeys(keys);

console.log(populateArrayData(array2, 'key', 'number', flattenedKeys));
  
  
  

score:1

const array1 = {
                key1: 7,
                key2: 1,
                key3: 37,
               };

const array2 = [
  {
      title: 'Some Title 1',
      key: 'key1',
      number: '',
      icon: require('../../assets/some2.png')
  },
  {
      title: 'Some Title 2',
      key: 'key2',
      number: '',
      icon: require('../../assets/some1.png')
  },
  {
      title: 'Some Title 3',
      key: 'key3',
      number: '',
      icon: require('../../assets/some3.png')
  },
];

array2.forEach(item=>{
  item.number=array1[item.key]
})

Related Query

More Query from same tag