Array is one of the most commonly used data structure in any programming language, we often use array in different form, here we look at some of the frequently asked array questions during interview.
Array structure and basic principal remain same in all the language, there may be some syntax difference, and python array has more advanced built-in methods compare to other programming language.
If you are fresher or want to see how array structure looks in different programming language, then here are some quick references.
No matter what language you use, some basic principal of array data type that will remain same in all the language.
Yes, we can define an array without the array size, then keep adding element as required
var carList=new Array();
When we don’t define the size of an array, it becomes zero by default.
We can define array in multiple ways, look at following examples .
const stringArray = ['green', 'park', 'big', 'elephant', 'roaming'];
Finding duplicate item from array will have following process.
There are various way we can remove an item from array, here is a post about how to remove item from array with examples.
There are different ways we can search an element from an array, some built-in methods like find, filter etc. find will get the first matching element, when filter will get all the matching elements.
const words = ['green', 'park', 'elephant', 'roaming']; const result = words.filter(word => word.length > 5); console.log(result);
here is an example of how to search an element from array with examples.
var stringArray = ['green', 'park', 'elephant', 'roaming']; stringArray[1]="jungle";
In above example we have changed the value of second element stringArray[1]
from “park” to “jungle”.