Unable to change the objects key value using lodash

Viewed 3085
var flagsObj = {
  logical1Flag: false,
  operator1Flag: false,
  resourceLeftFlag: false,
  resource1Flag: false,
  resourceRightFlag: false,
};

in the object above i wanted to change the value of any one of them and make it to true and the rest i wanted to make it to false. i have used this function which is mentioned below, however i am able to change the value of the using the map values or foreach function but the original flagsobj is not getting changes.

function settingFlag(val, keyF) { 
   const trueVal = val;
   const falseVal = false;
   const assignedKey = keyF;

_.mapValues(this.flagsObj, (value, key) => {
  if (key === assignedKey) {
    value = true;
  } else {
    value = false;
  }
  // console.log(value);
  console.log(`
    Flags
    ====
    key ${key} value ${value}
  `);
});

or using the forEach to manipulate the data

_.forEach(this.flagsObj, (value, key) => {
  if (key === assignedKey) {
    value = true;
    console.log(`
    flags
    =====
    key ${key} value ${value}
    `);
  } else {
    value = false;
  }
});
console.log('::::: FLAGS :::: ', flagsObj);
}

both foreach or map values are changing the required values the but the original flagsObj is not getting changed.

any lodash function which would solve the problem is appreciated. i am using angular 1.5 es6 application

6 Answers
Related