in Javascript
JavaScript
x
8
1
const qstndata = Object.entries(user.qstn).map(([key, values], index) => ({
2
question_id: values._id,
3
qs_no: index + 1,
4
in_state: 0,
5
section_index: // here need to start with 1 if section_name changes
6
section_name: values.sectionname,
7
}));
8
if here values.sectionname
changes New Index number needed how i can achieve this section_index
Advertisement
Answer
JavaScript
1
12
12
1
let myindex = 0;
2
let secname ="";
3
const qstndata = Object.entries(user.qstn).map(([key, values], index) => ({
4
5
qs_no: index + 1,
6
sb_no :secname == values.sectionname?'': myindex =0 ,
7
ss_no: myindex = myindex+1,
8
secname :secname = values.sectionname ,
9
10
section_name: values.sectionname,
11
}));
12