두 개체가 있고 밑줄 j를 사용하여 고유 한 데이터 만 추출하려고합니다.두 개체를 비교하여 고유 한 데이터 만 반환
개체 1 (기본)
{
players: "Players: ",
tableLimit: "Table Limits:",
newCardBtn: "Add New Card",
existingCard: "Use existing one",
contactUs: "Contact Us",
test: {
table: 'test'
}
}
개체 2 (중복)
{
players: "Players: ",
tableLimit: "Table Limits:",
newCardBtn: "Add New Card",
existingCard: "Use existing one",
test: {
table: 'test'
}
}
최종 결과 덮어에서 누락 데이터 목록을 반환한다. 우리의 경우, 지금이이 때까지 contactUs: "Contact Us"
를 반환해야하지만 사용자 지정하지 않고 기본 객체의 모든 데이터를 반환 : 이것은으로 obj1 구문 분석
var def = {
players: "Players: ",
tableLimit: "Table Limits:",
newCardBtn: "Add New Card",
existingCard: "Use existing one",
contactUs: "Contact Us",
test: {
table: 'test'
}
}
var custom = {
players: "Players: ",
tableLimit: "Table Limits:",
newCardBtn: "Add New Card",
existingCard: "Use existing one",
test: {
table: 'test'
}
}
var out = JSON.stringify(Object.assign({}, def, custom));
fs.writeFile("./out.js", out);
내가 언급 알고 포스트는'underscore'를 사용하지 않는 ... 출력에 결과를 볼 수 있습니다. 대답이 ** ** 밑줄 만 ** 표시되도록하려면 거부하고 질문에 필요한 정보를 추가하십시오. 순수한 JS 버전을 사용해도 괜찮 으면 복제본을 받아 들여 다른 사람이이 게시물에 답변 할 수 없도록하십시오. – Rajesh