У меня есть ответ json, и я попытался получить имя пользователя и типы для пользователя. Который сейчас работает нормально. Я хочу добавить географическое имя вместе с именем пользователя как user1 <Geo1>
user2. Я пробовал как
const response = [
{
UserName: "User1",
Type: "type3",
Geo: "Geo1",
month: "May",
Week1: 2,
Week2: 1
},
{
UserName: "User2",
Type: "type2",
Geo: "Geo2",
month: "July",
Week1: 1
},
{
UserName: "User1",
Type: "type1",
Geo: "Geo1",
month: "Jun",
Week2: 1,
Week1: 1
},
{
UserName: "User1",
Type: "type2",
Geo: "Geo1",
month: "July",
Week3: 1
},
{
UserName: "User2",
Type: "type3",
Geo: "Geo2",
month: "May",
Week1: 2,
Week2: 1
},
{
UserName: "User2",
Type: "type1",
Geo: "Geo2",
month: "Jun",
Week2: 1,
Week1: 1
},
{
UserName: "User2",
Type: "type3",
Geo: "Geo3",
month: "May",
Week1: 2,
Week2: 1
},
];
const users = response.reduce((u, x) => {
if (!(x.UserName in u)) u[x.UserName] = {};
//if (!(x.UserName in u)) u[x.UserName]+u[x.Geo] = {}; my trial
const user = u[x.UserName];
//const Geouser = u[x.Geo];
//user[x.Geo] ;
if (!(x.Type in user)) user[x.Type] = {};
const { UserName, Geo,Type, month, ...weeks } = x;
user[x.Type][x.month.substring(0, 3)] = weeks;
return u;
}, {});
console.log(users);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Я поймал Uncaught SyntaxError: Invalid left-hand side in assignment
Ошибка