puiu91
11/4/2015 - 2:22 PM

JavaScript - Map vs Loop

JavaScript - Map vs Loop

    iMapped = []
    // you dont need to use map, you can do it yourself
    for (var i = 0; i < userSortColumn.length; i++) {
        // create object that contains the column celll value and the cells row index position
        iMapped[i] = {
            rowId: i,
            value: userSortColumn[i]
        }
    };

    debug(iMapped)

    // map the column array to add the row index that each cell belongs to
    var tableBodyMapped = userSortColumn.map(function(el, i) {
        return {
            rowId: i,
            value: el
        };
    })