Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loop through array and replace value on condition in Javascript

My array and pseudo code are as follows. I do need help with replacing values with stirng on condition. I tried below but can't move on.

var = [5000, 2000, 4030, 1100];

for (var i = 0; i < arR.length; i++) {
    if (arR.includes >= 5000) {
        (‘senior’);
    } else if (arR.includes >= 2000) {
        console.log(‘mid’);
    } else {
        (‘junior’);
    }
}

Expected result: var = [senior, mid, mid, junior];

like image 348
marcin2x4 Avatar asked Jul 06 '26 02:07

marcin2x4


1 Answers

let array = [5000, 2000, 4030, 1100];

let TransformedArray = array.map(item=>item>=5000 ? 'senior' : item>=2000 ? 'mid' : 'junior');

console.log(TransformedArray);
like image 152
cybercoder Avatar answered Jul 08 '26 17:07

cybercoder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!