Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / pas2js / 2019-06

High

2 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

warleyalex

It seems there is an issue with High

========
var
  fruits : array of String = ('Banana', 'Orange', 'Apple', 'Mango',
'Banana', 'Abacate', 'Apple');
begin
  TJSArray(fruits).push('kiwi');
  for Index := Low(fruits) to High(fruits) do
     console.log( fruits[Index] );
end;
========
JS output
//-------------
$mod.fruits.push("kiwi");
for ($mod.Index = 0; $mod.Index <= 6; $mod.Index++)
window.console.log($mod.fruits[$mod.Index]);

console output:
------------------
Banana
Orange
Apple
Mango
Banana
Abacate
Apple

//---the correct should be-------------------------
$mod.fruits.push("kiwi");
for ($mod.Index = 0; $mod.Index < $mod.fruits.length; $mod.Index++)
window.console.log($mod.fruits[$mod.Index]);

Banana
Orange
Apple
Mango
Banana
Abacate
Apple
kiwi

ahn, if we change High to Length, it works as expected.

  TJSArray(fruits).push('kiwi');
  for Index := Low(fruits) to Length(fruits) do
     console.log( fruits[Index] );
it translates corretly
$mod.fruits.push("kiwi");
    for ($mod.Index = 0; $mod.Index <= 7; $mod.Index++)
window.console.log($mod.fruits[$mod.Index]);

---------
Banana
Orange
Apple
Mango
Banana
Abacate
Apple
kiwi

Reply by email

Mattias Gaertner
to warleyalex
Show quoted text 18 lines
It seems there is an issue with High ======== var fruits : array of String = ('Banana', 'Orange', 'Apple', 'Mango', 'Banana', 'Abacate', 'Apple'); begin TJSArray(fruits).push('kiwi'); for Index := Low(fruits) to High(fruits) do console.log( fruits[Index] ); end; ======== JS output //------------- $mod.fruits.push("kiwi"); for ($mod.Index = 0; $mod.Index <= 6; $mod.Index++) window.console.log($mod.fruits[$mod.Index]);

Fixed.

Mattias

Reply by email