JavaScript 2022

Term 3 Wednesday

May - July 2022

This site will be updated live during the sessions

Week 3 (c) Array Map Method

		
001let serials = ['101','102','103','104','105'];
		
002
		
003
		
004// we need to add a prefix, say xbox
		
005
		
006
		
007let xboxSerials = serials.map(serial => {
		
008	return 'xbox-'+serial;
		
009});
		
010
		
011// logging the entire array, using the toString() method to display contents
		
012console.log(xboxSerials.toString());
		
013
		
014// NOTE! we have created a new array, serials array is unchanged
		
015console.log(serials.toString());
		
016
		
017//overwriting the original array
		
018serials = serials.map(serial => {
		
019	return 'ps5-'+serial;
		
020})
		
021
		
022console.log(serials.toString());
		
023
		
024/*							
		
025
		
026
		
027// alternatively
		
028
		
029let xboxSerials = serials.map(function(el) {
		
030	return 'xbox'+el;
		
031})
		
032
		
033
		
034
		
035
		
036// we can also rewrite the original array:
		
037
		
038*/