Click the below button to see what object is inside the Array Element
Create a new product :
Create new product price :
- In this Sample program i will need to create 2 separate function. The first function is to create the instance of the Object the second function is to print out object store inside the array.
- First declare a new array variable call var newProduct = ; this will be use to store instances created using the object later in the program
- Declare the new object / constructor call function myProduct(Product,Price) and declare 2 parameter ” Product,Price “in the parentheses
- Create the function that will create a new object , and push it into the array after the user input the parameter.
- When the Create object button is click it will call the “cObject(createProduct,productprice)”function
- Then the Function will get the User Input from the text box and assign the value into “createProduct,productprice “
- ” newProduct.push(new myProduct(createProduct,productprice)); “ in this command line it will create a new “myProduct “ instance and push the value into the “newProduct ” Array.
- Now lets create the print out object function call ” outArray() ”
- First we need to know how much is the length of the Array and then loop through every single element in the Array
- Then we need to loop through, the object to check how many element contains inside an object
- Finally the program will print out the results