Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #38395 > unrolled thread
| Started by | JRough <janis.rough@gmail.com> |
|---|---|
| First post | 2020-05-09 16:49 -0700 |
| Last post | 2020-05-12 14:09 -0700 |
| Articles | 7 — 4 participants |
Back to article view | Back to comp.lang.javascript
create 2 dimension tuple in Typescript and access items JRough <janis.rough@gmail.com> - 2020-05-09 16:49 -0700
Re: create 2 dimension tuple in Typescript and access items JJ <jj4public@vfemail.net> - 2020-05-10 19:56 +0700
Re: create 2 dimension tuple in Typescript and access items JRough <janis.rough@gmail.com> - 2020-05-10 06:09 -0700
Re: create 2 dimension tuple in Typescript and access items Arno Welzel <usenet@arnowelzel.de> - 2020-05-10 22:56 +0200
Re: create 2 dimension tuple in Typescript and access items JRough <janis.rough@gmail.com> - 2020-05-11 11:06 -0700
Re: create 2 dimension tuple in Typescript and access items JRough <janis.rough@gmail.com> - 2020-05-11 11:52 -0700
Re: create 2 dimension tuple in Typescript and access items "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2020-05-12 14:09 -0700
| From | JRough <janis.rough@gmail.com> |
|---|---|
| Date | 2020-05-09 16:49 -0700 |
| Subject | create 2 dimension tuple in Typescript and access items |
| Message-ID | <e5d1fdb0-c8d9-4077-9cd0-445042c1d2d2@googlegroups.com> |
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++){
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) {
document.getElementById("pName1").innerHTML = productlist[i][1] ;
document.getElementById("pPrice1").innerHTML = productlist[i][2];
document.getElementById("pAvailable1").innerHTML= productlist[i][3];
}else {
document.getElementById("pName2").innerHTML = productlist[i][1] ;
document.getElementById("pPrice2").innerHTML = productlist[i][2];
document.getElementById("pAvailable2").innerHTML= productlist[i][3];
}
}
thank-you
[toc] | [next] | [standalone]
| From | JJ <jj4public@vfemail.net> |
|---|---|
| Date | 2020-05-10 19:56 +0700 |
| Message-ID | <1gjb11wmd1kna.1w1zqopuov70t.dlg@40tude.net> |
| In reply to | #38395 |
On Sat, 9 May 2020 16:49:36 -0700 (PDT), JRough wrote: > 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? What error?
[toc] | [prev] | [next] | [standalone]
| From | JRough <janis.rough@gmail.com> |
|---|---|
| Date | 2020-05-10 06:09 -0700 |
| Message-ID | <a4b9c9c7-4a50-47e2-b742-62101b6a6578@googlegroups.com> |
| In reply to | #38396 |
ERROR: Declaration or Statement expected. On Sunday, May 10, 2020 at 5:56:17 AM UTC-7, JJ wrote: > On Sat, 9 May 2020 16:49:36 -0700 (PDT), JRough wrote: > > 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? > > What error?
[toc] | [prev] | [next] | [standalone]
| From | Arno Welzel <usenet@arnowelzel.de> |
|---|---|
| Date | 2020-05-10 22:56 +0200 |
| Message-ID | <hhr838FelohU1@mid.individual.net> |
| In reply to | #38395 |
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
[toc] | [prev] | [next] | [standalone]
| From | JRough <janis.rough@gmail.com> |
|---|---|
| Date | 2020-05-11 11:06 -0700 |
| Message-ID | <e58e0191-c2cc-4faa-bb94-7c2a97e39fd6@googlegroups.com> |
| In reply to | #38395 |
ok thanks for your input on the script, for the typescript error, it works now, I took out the word array, i.e,
const productlist:( number | string| number|string| string| string)[];
On Saturday, May 9, 2020 at 4:49:42 PM UTC-7, JRough wrote:
> 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++){
> 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) {
> document.getElementById("pName1").innerHTML = productlist[i][1] ;
> document.getElementById("pPrice1").innerHTML = productlist[i][2];
> document.getElementById("pAvailable1").innerHTML= productlist[i][3];
> }else {
> document.getElementById("pName2").innerHTML = productlist[i][1] ;
> document.getElementById("pPrice2").innerHTML = productlist[i][2];
> document.getElementById("pAvailable2").innerHTML= productlist[i][3];
>
> }
> }
>
> thank-you
[toc] | [prev] | [next] | [standalone]
| From | JRough <janis.rough@gmail.com> |
|---|---|
| Date | 2020-05-11 11:52 -0700 |
| Message-ID | <bf650290-7dbd-4c0f-b5fb-a0a5567fd190@googlegroups.com> |
| In reply to | #38399 |
Actually Tuple should look like this I think:
let productlist:( string| number|string| string| string)[];
productlist = [ "Samsung Galaxy Note 7",59000, 'Available',"url('MobileCart_Images_part1/SamsungGalaxy_Gold.jpg')" ];
productlist.push( 'Samsung Galaxy S6 Edge',53499,'Available', "url('MobileCart_Images_part1/samsung_edge_silver.JPG')");
productlist.push( 'Nokia Lumia i640XL', 14990, 'Out of Stock',"url('MobileCart_Images_part1/lumia_640xl.jpg')" );
On Monday, May 11, 2020 at 11:06:48 AM UTC-7, JRough wrote:
> ok thanks for your input on the script, for the typescript error, it works now, I took out the word array, i.e,
> const productlist:( number | string| number|string| string| string)[];
>
> On Saturday, May 9, 2020 at 4:49:42 PM UTC-7, JRough wrote:
> > 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++){
> > 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) {
> > document.getElementById("pName1").innerHTML = productlist[i][1] ;
> > document.getElementById("pPrice1").innerHTML = productlist[i][2];
> > document.getElementById("pAvailable1").innerHTML= productlist[i][3];
> > }else {
> > document.getElementById("pName2").innerHTML = productlist[i][1] ;
> > document.getElementById("pPrice2").innerHTML = productlist[i][2];
> > document.getElementById("pAvailable2").innerHTML= productlist[i][3];
> >
> > }
> > }
> >
> > thank-you
[toc] | [prev] | [next] | [standalone]
| From | "Michael Haufe (TNO)" <tno@thenewobjective.com> |
|---|---|
| Date | 2020-05-12 14:09 -0700 |
| Message-ID | <6429b7fc-6ec8-4e2f-90b2-e3d9d0217e8f@googlegroups.com> |
| In reply to | #38395 |
On Saturday, May 9, 2020 at 6:49:42 PM UTC-5, JRough wrote:
> 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)[]; *****
If it's supposed to be an array of tuples then the type should look like this:
```ts
const productlist: [number,string,number,boolean,string,string][] = [];
```
You'll need to fix the type of your populating though:
```ts
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."],
[433,'SamsungGalaxyS6Edge',53499,'Available',"url('MobileCart_Images_part1/samsung_edge_silver.JPG')", "Samsung Galaxy Edge blah blah blah"],
[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++){
> 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) {
> document.getElementById("pName1").innerHTML = productlist[i][1] ;
> document.getElementById("pPrice1").innerHTML = productlist[i][2];
> document.getElementById("pAvailable1").innerHTML= productlist[i][3];
> }else {
> document.getElementById("pName2").innerHTML = productlist[i][1] ;
> document.getElementById("pPrice2").innerHTML = productlist[i][2];
> document.getElementById("pAvailable2").innerHTML= productlist[i][3];
>
> }
> }
>
Maybe instead something like:
```ts
productlist.forEach(([,name, price, available], i) => {
document.getElementById(`pName${i}`).innerHTML = name
document.getElementById(`pPrice${i}`).innerHTML = price
document.getElementById(`pAvailable${i}`).innerHTML = available
})
```
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web