I mean: I have two arrays, number, and name
const number = ['91xxxx','1xxxx','92xxxx']
const name = ['Abhi','Arun','Aaron']
Here I want to order these two arrays in the following manner:
1st number in the array that is number[0], its name must be name[0] and number[1], for name[1], like that.
But That arrays are user preference, what I mean is users can add their number and name there unlimitedly but I want to keep in the above manner, How should I do????
I have made a code:
async function getAllOwners() {
var nam = ''
var num = ''
number.map(async (nu) => {
num = nu
})
name.map(async (na) => {
nam = na
})
return nam for num;
}
But I don't know whether this works or not.
I suggest that you will have a different function for pushing new data and retrieving the data.
function getAllOwners() {
return name.map((_name,index)=>_name+' '+number[index])
}// Output: [ 'Abhi 91xxxx', 'Arun 1xxxx', 'Aaron 92xxxx' ]
*Note that there's no need for the async keyword for there's no asynchronous operation here.
function addOwner(_name,num){
name.push(_name)
number.push(num)
}