Skip to content
Advertisement

Add more element to a 3×3 2D array

I’m writing an inventory list program, that provides the user with option of adding an item to the list of exiting the program. To add an item the user enters 1 and is promoted to enter the item details( item name, price and quantity of the items). The information enter by the user is entered into a 3×3 2D array table, which already has a few values in it. The problem here is that I am finding it difficult to update/add new elements to the 3×3 2D array table. I’ve searched the internet for solutions, but I couldn’t find any. Below is a code snippet of the 3×3 2D array table I wrote.

JavaScript

P.S I’m new to arrays and don’t really know how to use them.

Advertisement

Answer

Here is a break-down of one way this can be done. Read the comments in code:

JavaScript

When run, your console output should look something like this:

JavaScript

Consider using a List or an ArrayList as these can grow and shrink dynamically.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement