Я пытаюсь преобразовать свой массив в этот формат. У меня есть такой массив
0: {name: "client_name", type: "INPUT", value: "John Doe"}
1: {name: "detail_note_editor", type: "TEXTAREA", value: "Verbal consent obtained↵MH checked and any changes…/ Medium/ Low↵Oral Cancer Risk: High/ Medium/ Low"}
2: {name: "option_title", type: "INPUT", value: "HPC"}
3: {name: "customDropDown", type: "SELECT", value: "For the last few weeks"}
4: {name: "option_title", type: "INPUT", value: "Diagnosis"}
5: {name: "customDropDown", type: "SELECT", value: "peridontal disease"}
6: {name: "detail_note_editor", type: "TEXTAREA", value: "Skeletal : ↵Lips : comp / Incomp↵Crowding :↵Incisor class :↵OJ :↵Overbite :↵X bites :"}
7: {name: "option_title", type: "INPUT", value: "Toothbrushing"}
8: {name: "customDropDown", type: "SELECT", value: "0x per day"}
Я хочу, чтобы данные плана были в этом формате и напрямую заполнялись в одно текстовое поле
Client Name: John Doe
Verbal consent obtained
HPC: For the last few weeks
Diagnosis: peridontal disease
Skeletal : Skeletal : ↵Lips : comp / Incomp↵Crowding :↵Incisor class :↵OJ :↵Overbite :↵X bites :
Toothbrushing: 0x per day
после попытки я получаю этот результат
["Verbal consent obtained↵MH checked and any changes…/ Medium/ Low↵Oral Cancer Risk: High/ Medium/ Low", Array(2), Array(2), Array(2), Array(2), "Skeletal : ↵Lips : comp / Incomp↵Crowding :↵Incisor class :↵OJ :↵Overbite :↵X bites :", Array(2), Array(2)]
0: "Verbal consent obtained↵MH checked and any changes required have been noted↵PCO: nil / pain / tenderness↵HPC: nil/ for the last few days / for the last few weeks↵diet: eats no sugar/ regularly has sugar↵alcohol consumption: 5 units per week/ 10 units per week↵smoking: 5 per day"
1: (2) ["", "HPC: "]
2: (2) ["", ": For the last few weeks"]
3: (2) ["", "Diagnosis: "]
4: (2) ["", ": peridontal disease"]
5: "Skeletal : ↵Lips : comp / Incomp↵Crowding :↵Incisor class :↵OJ :↵Overbite :↵X bites :"
6: (2) ["", "Toothbrushing: "]
7: (2) ["", ": 0x per day"]
length: 8
let Arr = [{name: "client_name", type: "INPUT", value: "John Doe"},{name: "detail_note_editor", type: "TEXTAREA", value: "Verbal consent obtained↵MH checked and any changes…/ Medium/ Low↵Oral Cancer Risk: High/ Medium/ Low"},{name: "option_title", type: "INPUT", value: "HPC"},{name: "customDropDown", type: "SELECT", value: "For the last few weeks"},{name: "option_title", type: "INPUT", value: "Diagnosis"},{name: "customDropDown", type: "SELECT", value: "peridontal disease"},{name: "detail_note_editor", type: "TEXTAREA", value: "Skeletal : ↵Lips : comp / Incomp↵Crowding :↵Incisor class :↵OJ :↵Overbite :↵X bites :"},{name: "option_title", type: "INPUT", value: "Toothbrushing"},{name: "customDropDown", type: "SELECT", value: "0x per day"}];
let newArr = [];
$.each(Arr, function(key, value){
if(value.name == "detail_note_editor"){
newArr.push(value.value);
}
if(value.name == "option_title" || value.name == "customDropDown"){
let textarea = "";
let input = "";
let select = "";
if(value.type == 'TEXTAREA'){
textarea += value.value;
}
if(value.type == 'INPUT'){
input += value.value;
}
if(value.type == 'SELECT'){
select += value.value;
}
let newData = input + ": " + select;
console.log(newData);
newArr.push([textarea, newData]);
}
console.log(value);
});
console.log(newArr);