Need assistance on separating an array using the split method. The array contains objects with properties such as name, course1, course2, and course3. Only the courses with text in their content along with a plus sign should be separated into an array using the split property. Each course object should include its identifier, credit, and note. Here is the original array:
Please help me, thank you.
I attempted to write some code but it's not working for me
//this is my array
var student: [
{
'name' : 'ivan hambi apaza',
'course1' : 'HISTORIA DE LA DANZA+2+16',
'course2' : 'HISTORIA+3+17',
'course3' : '',
}
],
//a step that I was doing but it does not come out
studentCourses(){
var newArr = [...this.student]
newArr.map(el => {
return el.course1 = el.course1.split('+')
})
newArr.map(el => {
return el.course2 = el.course2.split('+')
})
newArr.map(el => {
return el.course3 = el.course3.split('+')
})
return newArr
}
console.log(studentCourses())
Expected result:
[
{
'name':'ivan hambi apaza',
'courses':[
{'course':'HISTORIA DE LA DANZA','credit':2,'note':16},
{'course':'HISTORIA','credit':3,'note': 17},
]
}
]