M1 = [{ "name": "Имя1", "id": "5" }, { "name": "Имя2", "id": "7" }];
<!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>ГГ</title> </head> <body> <script> function obj(n){ var arr = []; for(var i = 0; i < n; i++){ var obj = {}; obj.name = "Имя"+(i+1); obj.id = 5+2*i+''; arr.push(obj); } return arr; } var yourObj = obj(2); </script> </body> </html>