프로그래밍/JavaScipt

javascript object equal 객체비교하기

p-a-r-k 2017. 12. 27. 18:57
반응형

리스트 > 변경값만을 빼내기위해서 사용


function isEquivalent(a, b) {
	var aProps = Object.getOwnPropertyNames(a);
	var bProps = Object.getOwnPropertyNames(b);

	if (aProps.length != bProps.length) {
	  return false;
	}

	for (var i = 0; i < aProps.length; i++) {
	  var propName = aProps[i];
	  if (a[propName] !== b[propName]) {
			return false;
	  }
	}

	return true;
}

//사용 예
if(!isEquivalent(objectA[i], objectB[i])){
	//오브젝트가 다르면 처리하는 구문
}
반응형