Time Complexity
So, I'm going to be explaining time complexity to the best of my knowledge.
Time complexity is simply the amount of time it takes to run a particular code, and I'm going to be explaining which and which takes time and which does not. Now, by default, JavaScript provides us with two structures, which are Arrays([]), and Object({}).
Now, the amount of time it takes to load a particular code in an array may take longer depending on the way you choose to go about it. For example, we want to add a new element to an array, you can either use the .push() method to do so, or the .unshift() method. While push adds new element from the back, unshift add from the front. Using unshift will take time to execute, compared to push, because while unshift is adding from the front, it changes and iterates through the array to give each and every one of them an index position. And push just adds from the back and not have to go through that process.
Now, for Objects, there are really nothing that could cause slow execution of task, as we can easily access anything in it without having to iterate through it like an array does.
Top comments (0)