通过api修改数组:添加新的密钥Salary。 年龄小于或等于23岁,因此工资应为23,000, 23至27岁之间的年龄工资应该是27,000 年龄大于27岁工资应为500,000 数组的打印是否正确,因为我没有得到任何输出。 值被推送了吗?
var employee=[{"firstName":"Zahir","lastName":"Alam","Age":25,"Company":"Switchme","Role":"Developer","Department":"Tech","Head":{"Id":3,"Name":"Sourasis Roy"}},{"firstName":"Amith","lastName":"Manniken","Age":25,"Company":"Switchme","Role":"Developer","Department":"Tech","Head":{"Id":3,"Name":"Sourasis Roy"}},{"firstName":"Sourasis","lastName":"Roy","Age":28,"Company":"Switchme","Role":"CTO"},{"firstName":"Aditya","lastName":"Mishra","Age":29,"Company":"Switchme","Department":"Tech","Role":"CEO"},{"firstName":"Priti","lastName":"Lata","Age":24,"Company":"Switchme","Role":"HR"},{"firstName":"Sumita","lastName":"Nath","Age":24,"Company":"Switchme","Role":"HLA Head","Department":"Crm"},{"firstName":"Tarini","lastName":"Khanna","Age":22,"Company":"Switchme","Role":"Content Writer"},{"firstName":"Abhisek","lastName":"Soni","Age":23,"Company":"Switchme","Role":"HLA","Department":"Crm","Head":{"Id":5,"Name":"Sumita Nath"}},{"firstName":"Ankit","lastName":"Pump","Age":23,"Company":"Switchme","Role":"HLA","Department":"Crm","Head":{"Id":5,"Name":"Sumita Nath"}},{"firstName":"Pogo","lastName":"Laal","Age":23,"Company":"Switchme","Role":"Designer"},{"firstName":"Sabina","lastName":"Sekh","Age":28,"Company":"Switchme","Role":"HLA Head","Department":"Crm"},{"firstName":"Sanjay","lastName":"Poudal","Age":24,"Company":"Switchme","Role":"HLA Head","Department":"Crm","Head":{"Id":10,"Name":"Sabina Sekh"}}];
$(document).ready(function(){
$.each( employee, function( key, value ) {
if(value["Age"] <= 23) {
var obj = {};
obj[Salary] = 23000;
employee.push(obj);
}
else if(value["Age"] > 23 && value["Age"] < 27) {
var obj2 = {};
obj2[Salary] = 27000;
employee.push(obj2);
}
else if(value["Age"] > 27) {
var obj3 = {};
obj3[Salary] = 500000;
employee.push(obj3);
}
});
$.each(employee, function(index, value){
$("#modfy").append(index + ": " + value + '<br>');
});
});
<div class="modfy"></div> //this is my html code