Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Arno Welzel Newsgroups: comp.lang.javascript Subject: Re: create 2 dimension tuple in Typescript and access items Date: Sun, 10 May 2020 22:56:08 +0200 Lines: 71 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Trace: individual.net EeAkhiJUGBkO9IXbWlwTjwNQNk+HNVNnIeSwfNvUzkj1EgRpEk Cancel-Lock: sha1:Bus79F/Xl/WtjjmYgaSoPaqwKD4= In-Reply-To: Xref: csiph.com comp.lang.javascript:38398 JRough: > I have 3 rows of data , I want individual items inserted into web > page , but on the first line where I define the tuple , I get an > error and can't compile typescript? > > const productlist: Array( number | string| number|boolean| string| > string)[]; ***** > > productlist.push(431,"SamsungGalaxyNote7",59000,'Available',"url('MobileCart_Images_part1/SamsungGalaxy_Gold.jpg')","Samsung > Galaxy Note 7 is a stylish mobile you can ever have. It has 64GB > memory." ); > > productlist.push(433,'SamsungGalaxyS6Edge',53499,'Available',"url('MobileCart_Images_part1/samsung_edge_silver.JPG')", > "Samsung Galaxy Edge blah blah blah"); > > productlist.push(434,'NokiaLumiai640XL',14990,'OutofStock',"url('MobileCart_Images_part1/lumia_640xl.jpg')", > "Nokia Lumia 640XL blah blah blah" ); > > > > And here is my script to insert the individual items into the html page: > > for ( var i = 0; productlist.length > i++){ This makes no sense and. What do you think this statement does? Probably you mean this: for (var i = 0; i < productlist.length; i++) { > if ( i = 0){ If you want to compare things, don't use an assignment operator. The correct way would be: if (i == 0) { > document.getElementById("pName0").innerHTML = productlist[i][1] ; > document.getElementById("pPrice0").innerHTML = productlist[i][2]; > document.getElementById("pAvailable0").innerHTML= productlist[i][3]; > } else if( i = 1) { See above - you don't want to assign the value 1 to the variable i but *compare* i and 1: } else if (i == 1) { > document.getElementById("pName1").innerHTML = productlist[i][1] ; > document.getElementById("pPrice1").innerHTML = productlist[i][2]; > document.getElementById("pAvailable1").innerHTML= productlist[i][3]; > }else { Try to be consistent in your code style - always put spaces between curly braces and the following word: } else { > document.getElementById("pName2").innerHTML = productlist[i][1] ; > document.getElementById("pPrice2").innerHTML = productlist[i][2]; > document.getElementById("pAvailable2").innerHTML= productlist[i][3]; > > } > } It looks like you don't have a lot of experience with ECMAScript. Maybe you should do some more training. -- Arno Welzel https://arnowelzel.de