Вам не нужно создавать новый объект, только добавьте свойство для объекта значения в каждом цикле.Другая проблема:
Вы ставите class="modify"
, но используете в качестве идентификатора #modify.И в каждом цикле вам нужно использовать значение в качестве объекта.
$(".modfy").append(++index + ". " + value.firstName + ": " + value.lastName + ": " + value.Age + ": " + value.Company + ": " + value.Role + ": " + value.Department + ": " + value.Salary + '<br>');
Если вы хотите распечатать каждый объект, так как ваше требование нужно только $(".modfy").append(JSON.stringify(value));
или другим способом, если вы хотите отобразить как массив $(".modfy").append(JSON.stringify(employee));
$(document).ready(function(){
$.each( employee, function( key, value ) {
if(value["Age"] <= 23) {
//var obj = {};
value["Salary"] = 23000;
//employee.push(obj);
}
else if(value["Age"] > 23 && value["Age"] < 27) {
//var obj2 = {};
value["Salary"] = 27000;
//employee.push(obj2);
}
else if(value["Age"] > 27) {
//var obj3 = {};
value["Salary"] = 500000;
//employee.push(obj3);
}
});
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 = {};
value["Salary"] = 23000;
//employee.push(obj);
}
else if(value["Age"] > 23 && value["Age"] < 27) {
//var obj2 = {};
value["Salary"] = 27000;
//employee.push(obj2);
}
else if(value["Age"] > 27) {
//var obj3 = {};
value["Salary"] = 500000;
//employee.push(obj3);
}
});
//console.log(employee)
// $.each(employee, function(index, value){
// $(".modfy").append(++index + ". " + value.firstName + ": " + value.lastName + ": " + value.Age + ": " + value.Company + ": " + value.Role + ": " + value.Department + ": " + value.Salary + '<br>');
//$(".modfy").append(JSON.stringify(value));
//});
$(".modfy").append(JSON.stringify(employee));
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="modfy"></div>