Vansh Motors Pvt. Ltd.
Explore the role of arrays in our factory operations.
Table of contents
Location : Ranchi, Jharkhand Time: 09:52
👨💼 Manager: Hey, Good morning Boss! What’s Up ?
👨🏿💼 Boss: Shuuuut upp😡😡. I asked you yesterday that I wanted to get the list of all the cars which are ready for delivery. Where is it ?
🧑💼Manager: Sorry Boss🥲. Actually I was busy with somthing else, so I forgot.
👨🏿💼 Boss: You are firedddd😡😡😡
🧑💼Manager: No No Bosss, I’m really sorry. I’ll get it done by 11:00 pm.
👨🏿💼 Boss: This is your last warning!
🧑💼Manager: What should I do now ? 🤔
👷🏻 Worker: I’ve got an idea💡.
🧑💼Manager: What ?
👷🏻 Worker: Why not use an array to store the car details, so that it would be easier for you to access and manage it and it would also save your time.⏲️
🧑💼Manager: Miracle Miracle!! Thank you my friend. I’m gonna increase your salary by 20%.
Time: 09:55
Manager called the owner of Array store.
🧑💼 Manager: Hey friend! I am the Manager of Vansh Motors and I am in emergency, I wanted to list the details of our cars inside an array so that the accessebility increases and it becomes easier for me to handle it.
🧔🏻♂️ Owner: Alright! take it, but I’ll charge a sum of $20/hr.
🧑💼Manager: It’s OK!
🧔🏻♂️ Owner: Let’s create your array const VanshCars = []
.Here is your array named VanshCars.
🧑💼 Manager: Heyyyy Worker! Come here faster… Push the cars inside this array and store them.
👷🏻 Worker: Pushing sir! VanshCars.push(‘VanshM1‘)
Tough day at work😓
🧑💼 Manager: Not a single one you fool! Push all of them.😡
👷🏻Worker:Alright! VanshCars.push(‘VanshM1GT‘,‘VanshS2‘,’VanshM3GT’,'VanshSuperA1', 'VanshS4')
Here it is sir.
🧑💼 Manager: Get me the total number of cars pushed inside the array.
👷🏻Worker: Oohhh nooo! More work to do😓 Here is the total size VanshCars.length
🧑💼 Manager: Only 5 cars 🫨🫨!! You need to work harder otherwise I’m gonna fire you from the job😡
👷🏻Worker: 😭😭😭
🧑💼 Manager: What the hell have you done ???? You pushed the wrong car at the end. You need to add VanshS4 at the front and not in the end. Fix it 😡
👷🏻Worker: 😓😓 I’m gonna runaway from this place. This work is so boring and my manager is so rude. But I’ll have to do it for my family.
Let me just pop out the last car and add it at the front. VanshCars.pop()
I’ve got ‘VanshS4‘
VanshCars.unshift(‘VanshS4‘)
.Here is your new array sir.
🧑💼Manager: Let me check. Ok it’s Good. Now get me the position(index) number of ‘VanshM3GT‘
👷🏻Worker: Sure Boss. VanshCars.indexOf(‘VanshM3GT‘)
It’s 3 sir.
🧑💼Manager: What car is there at position 4 ?
👷🏻Worker: Let me see. VanshCars.at(4)
. Sir it’s ‘VanshSuperA1‘
🧑💼 Manager: Just check if the array includes our newest arrival ‘VanshModel1‘.
👷🏻Worker: OK! VanshCars.includes(‘VanshModel1‘)
. No sir it’s not there
🧑💼Manager: I want to see the names of all the cars in uppercase .
👷🏻Worker: That’s a tough work. I need to go to every car and make it uppercase.
const newVanshCars = VanshCars.map((car)=>car.toUpperCase())
🧑💼Manager: Alright Worker! I’m impressed by your job. You are doing great.👍🏻
👷🏻Worker: Thank you so much sir! 😁😁
👨🏿💼 Boss: Hey Manager! How is the work going on ? Just remember the deadline. I wan’t it to be finished by 11:00
🧑💼Manager: Don’t worry boss, I’ll get it done before time.
👨🏿💼 Boss: Let’s see.
👨🏿💼 Boss: I am giving you a list of new arrivals as well. Just add them in the list.
🧑💼Manager: Let me just ask the worker to do so.
🧑💼Manager: Hey Worker! Just add this new list with the previous one.
👷🏻Worker: Oh! It’s so simple. I’ll just need to concat them. const newCarsList = VanshCars.concat(VanshNewArrivals)
. Here’s the new list sir!
🧑💼Manager: Boss is asking me to filter out all the GT cars from the list. Do it Worker!
👷🏻Worker: Alright🥱🥱. Work! Work! Work!
const filteredCarsList = newCarsList.filter((car)=>car.includes(‘GT‘))
👷🏻Worker: Sir its done
🧑💼Manager: Alright you did a great job today. You saved my life🙂
Time: 10:55
Manager at Boss’s room.
Knock Knock!!
👨🏿💼 Boss: Who’s there ?
🧑💼Manager: It’s me, the Manager.
👨🏿💼 Boss: Come in.
🧑💼Manager: Sir the work is done and here’s the report.
👨🏿💼 Boss: You did it on time. Impressive🙂🙂
🧑💼Manager: Sir the worker did a lot of hard work today. I request you to give him some bonus.
👨🏿💼 Boss: Sure.
THE END!
Conclusion
Through this short story, We got to learn about arrays and its different methods. Arrays are used to store a collection of data under a single variable name. Its provides us a lot of methods so that our work becomes easier. In order to learn more about them you can check out mdn docs link given below
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array