How to judge the following table by the attribute values of an array object and split it into two arrays

as shown in the figure, determine the subscript of the object name in the array and split the array into two arrays from the following table. Thank you

Mar.16,2021

let arr = [{
    fieldName: 'hello',
    valueVOs: []
}, {
    fieldName: 'hello',
    valueVOs: []
}, {
    fieldName: '',
    valueVOs: []
}, {
    fieldName: 'hello',
    valueVOs: []
}, {
    fieldName: 'hello',
    valueVOs: []
}]
function trans (arr) {
    let index = arr.findIndex(a => a.fieldName === '') // 
    if (index !== -1) {
        return [arr.slice(0, index), arr.slice(index)]
    }
    return [arr.slice()]
}
trans(arr)



const getNewArray = (data) => {
    let newArray = [[],[]];
    data.forEach((val) => {
        if (val.fieldName === "") {
            newArray[1].push(val)
        } else {
            newArray[0].push(val)
        }
    })

    return newArray
}
getNewArray(data)
Menu