dimanche 28 février 2021

I'm trying to make an if statements that sorts different types of values in my array of objects

I want a code that gives me the value of the objects properties value, and then take the if statement that has that value so it gets the correct console.log.

  var i = 0;
if(stoneData[i].hasOwnProperty('type') == "moveTo" || stoneData[i].hasOwnProperty('type') == "lineTo") {
console.log('stoneData[' + i + '].type = ' + stoneData[i].type + ', stoneData[' + i + '].point = ' + stoneData[i].point + ', stoneData['+i+'].axis.x = ' + stoneData[i].axis.x + ', stoneData['+i+'].axis.y = ' + stoneData[i].axis.y);
} else if(stoneData[i].hasOwnProperty('type') == "quadraticCurveTo") {
  console.log('stoneData[' + i + '].type = ' + stoneData[i].type + ', stoneData[' + i + '].point = ' + stoneData[i].point + ', stoneData['+i+'].axis.curveX = ' + stoneData['+i+'].axis.curveX + ', stoneData['+i+'].axis.curveY = ' + stoneData['+i+'].axis.curveY + ', stoneData['+i+'].axis.x = ' + stoneData[i].axis.x + ', stoneData['+i+'].axis.y = ' + stoneData[i].axis.y);
} else {
  return "something went wrong";
}

I have tried different other methods also.

I can't find the correct way of finding (stoneData[index].type == value).

I have done programming less than a year, so I'm not so good with advance answers yet.

Aucun commentaire:

Enregistrer un commentaire