Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Question

Post Timeline

Copy edited (but more work is needed near "an delete elements"). Removed meta information (this belongs in comments).
Source Link
Peter Mortensen
  • 31.3k
  • 22
  • 110
  • 134

Javascript JavaScript 2D Array literatearray iteration through 1 Dimensionone dimension doesn't work

I've found some really useful guides on this site so i hope you can help me even further What am i doing? II have a exel based Productan Excel -based product list saved as .txt i. I load this into javascriptJavaScript as follows:

function make2DArray (pfad){
 var Daten = loadFile(pfad);
 var Array = createArray(Daten);
 return Array;
}
function createArray(data_in){
 var Zeilen = data_in.split("\n");
 var Spalten = new Array();
for (var i=0; i<Zeilen.length; i++)
 {
 Spalten = Zeilen[i].split("\t");
 Zeilen[i] = Spalten.splice(0,Spalten.length);
}
return Zeilen;
};
function loadFile(file_in)
{
var file_out;
$.ajax({
 type: type: "GET",
 url: url: file_in,
 dataType: dataType: 'text',
 async: async:  false,
 success: success: function(data){
 file_out = data;
 },
 error: function(){
 openDialog('Datei nicht gefunden', file_in + " konnte nicht gefunden werden.\n<br />Bitte wende dich an einen Troubleshooter oder Teamleader!");
 }
});
return file_out;
};

that'sThat's so that you knewknow how my Array is made... anyway

Anyway, with this iI have an Array[rows][cols] to work with now i. Now I have in array[rows][14] a price in array[rows][14] which iI want to compare i. I load one line which is the existing produkt (1d1D Array) and my 2d2D array:

function PackAusfiltern (arrzeile, arr) {
var Eingabearray = arr;
var Ausgabearray = "";
var BestandPreis = arrzeile[14];
BestandPreis = BestandPreis.replace(/,円/g, '.');
BestandPreis = parseFloat(BestandPreis);
//Here iI get the Priceprice of the existing Packagepackage which iI want to compare

And now to my Actual Problemactual problem: I want to literate througthrough every Rowrow, get the Valuevalue of column 14 and convert it to a number (some numbers are stored like "39,90", so iI need to change the "," to ".").

i get hereI always get an Errorerror here in this line:

var zwischenspeicher = Eingabearray[i][14]+"";

it SaysIt says something like "for the property '14' is no value get able" (german IE 9German Internet Explorer 9...) Here.

Here is the forfor loop which should get the value, make it a number, compare it an delete elements where already the second line already brings the error:

for (var i=0, j=Eingabearray.length; i<j; i++) {
 var zwischenspeicher = Eingabearray[i][14]+"";
 zwischenspeicher = zwischenspeicher.split(',').join('.');
 zwischenspeicher = parseFloat(zwischenspeicher);
 Eingabearray[i][14] = zwischenspeicher;
 if ((BestandPreis <= Eingabearray[i][14]) && Eingabearray[i][16] == 1)
 {
 var löschenPO = Eingabearray.indexOf(Eingabearray[i][17]); //find Find other pack code
 var löschenindex = Eingabearray.indexOf(löschenPO); // searchSearch other pack
 Eingabearray = Eingabearray.splice(löschenindex, 1); // deleteDelete other pack
 }
 };

justJust for information:

type(Eingabearray[i][14]); //= [object Number]
function type(obj){
alert(Object.prototype.toString.call(obj));
}

hopefully you get my bad English and the formatting works so you can tell me whatWhat stupid mistake i made^^ all the best and marry Christmashave I made?

Javascript 2D Array literate through 1 Dimension doesn't work

I've found some really useful guides on this site so i hope you can help me even further What am i doing? I have a exel based Product list saved as .txt i load this into javascript as follows:

function make2DArray (pfad){
 var Daten = loadFile(pfad);
 var Array = createArray(Daten);
 return Array;
}
function createArray(data_in){
 var Zeilen = data_in.split("\n");
 var Spalten = new Array();
for (var i=0; i<Zeilen.length; i++)
 {
 Spalten = Zeilen[i].split("\t");
 Zeilen[i] = Spalten.splice(0,Spalten.length);
}
return Zeilen;
};
function loadFile(file_in)
{
var file_out;
$.ajax({
 type: "GET",
 url: file_in,
 dataType: 'text',
 async: false,
 success: function(data){
 file_out = data;
 },
 error: function(){
 openDialog('Datei nicht gefunden', file_in + " konnte nicht gefunden werden.\n<br />Bitte wende dich an einen Troubleshooter oder Teamleader!");
 }
});
return file_out;
};

that's that you knew how my Array is made... anyway with this i have an Array[rows][cols] to work with now i have in array[rows][14] a price which i want to compare i load one line which is the existing produkt (1d Array) and my 2d array

function PackAusfiltern (arrzeile, arr) {
var Eingabearray = arr;
var Ausgabearray = "";
var BestandPreis = arrzeile[14];
BestandPreis = BestandPreis.replace(/,円/g, '.');
BestandPreis = parseFloat(BestandPreis);
//Here i get the Price of the existing Package which i want to compare

And now to my Actual Problem: I want to literate throug every Row, get the Value of column 14 and convert it to a number (some numbers are stored like "39,90" so i need to change the "," to ".")

i get here always an Error in line:

var zwischenspeicher = Eingabearray[i][14]+"";

it Says something like "for the property '14' is no value get able" (german IE 9...) Here is the for loop which should get the value, make it a number, compare it an delete elements where already the second line brings the error:

for (var i=0, j=Eingabearray.length; i<j; i++) {
 var zwischenspeicher = Eingabearray[i][14]+"";
 zwischenspeicher = zwischenspeicher.split(',').join('.');
 zwischenspeicher = parseFloat(zwischenspeicher);
 Eingabearray[i][14] = zwischenspeicher;
 if ((BestandPreis <= Eingabearray[i][14]) && Eingabearray[i][16] == 1)
 {
 var löschenPO = Eingabearray.indexOf(Eingabearray[i][17]); //find other pack code
 var löschenindex = Eingabearray.indexOf(löschenPO); // search other pack
 Eingabearray = Eingabearray.splice(löschenindex, 1); // delete other pack
 }
 };

just for information:

type(Eingabearray[i][14]); //= [object Number]
function type(obj){
alert(Object.prototype.toString.call(obj));
}

hopefully you get my bad English and the formatting works so you can tell me what stupid mistake i made^^ all the best and marry Christmas

JavaScript 2D array iteration through one dimension doesn't work

I have an Excel -based product list saved as .txt. I load this into JavaScript as follows:

function make2DArray (pfad){
 var Daten = loadFile(pfad);
 var Array = createArray(Daten);
 return Array;
}
function createArray(data_in){
 var Zeilen = data_in.split("\n");
 var Spalten = new Array();
for (var i=0; i<Zeilen.length; i++)
 {
 Spalten = Zeilen[i].split("\t");
 Zeilen[i] = Spalten.splice(0,Spalten.length);
}
return Zeilen;
};
function loadFile(file_in)
{
var file_out;
$.ajax({
 type: "GET",
 url: file_in,
 dataType: 'text',
 async:  false,
 success: function(data){
 file_out = data;
 },
 error: function(){
 openDialog('Datei nicht gefunden', file_in + " konnte nicht gefunden werden.\n<br />Bitte wende dich an einen Troubleshooter oder Teamleader!");
 }
});
return file_out;
};

That's so that you know how my Array is made...

Anyway, with this I have an Array[rows][cols] to work with. Now I have a price in array[rows][14] which I want to compare. I load one line which is the existing produkt (1D Array) and my 2D array:

function PackAusfiltern (arrzeile, arr) {
var Eingabearray = arr;
var Ausgabearray = "";
var BestandPreis = arrzeile[14];
BestandPreis = BestandPreis.replace(/,円/g, '.');
BestandPreis = parseFloat(BestandPreis);
//Here I get the price of the existing package which I want to compare

And now to my actual problem: I want to literate through every row, get the value of column 14 and convert it to a number (some numbers are stored like "39,90", so I need to change the "," to ".").

I always get an error here in this line:

var zwischenspeicher = Eingabearray[i][14]+"";

It says something like "for the property '14' is no value get able" (German Internet Explorer 9...).

Here is the for loop which should get the value, make it a number, compare it an delete elements where the second line already brings the error:

for (var i=0, j=Eingabearray.length; i<j; i++) {
 var zwischenspeicher = Eingabearray[i][14]+"";
 zwischenspeicher = zwischenspeicher.split(',').join('.');
 zwischenspeicher = parseFloat(zwischenspeicher);
 Eingabearray[i][14] = zwischenspeicher;
 if ((BestandPreis <= Eingabearray[i][14]) && Eingabearray[i][16] == 1)
 {
 var löschenPO = Eingabearray.indexOf(Eingabearray[i][17]); // Find other pack code
 var löschenindex = Eingabearray.indexOf(löschenPO); // Search other pack
 Eingabearray = Eingabearray.splice(löschenindex, 1); // Delete other pack
 }
 };

Just for information:

type(Eingabearray[i][14]); //= [object Number]
function type(obj){
alert(Object.prototype.toString.call(obj));
}

What stupid mistake have I made?

Javascript 2D Array literate through 1 Dimension dosn'tdoesn't work

Source Link
lunee
  • 84
  • 2

Javascript 2D Array literate through 1 Dimension dosn't work

I've found some really useful guides on this site so i hope you can help me even further What am i doing? I have a exel based Product list saved as .txt i load this into javascript as follows:

function make2DArray (pfad){
 var Daten = loadFile(pfad);
 var Array = createArray(Daten);
 return Array;
}
function createArray(data_in){
 var Zeilen = data_in.split("\n"); 
 var Spalten = new Array(); 
for (var i=0; i<Zeilen.length; i++)
 {
 Spalten = Zeilen[i].split("\t");
 Zeilen[i] = Spalten.splice(0,Spalten.length);
}
return Zeilen;
};
function loadFile(file_in)
{
var file_out;
$.ajax({
 type: "GET",
 url: file_in,
 dataType: 'text',
 async: false,
 success: function(data){
 file_out = data;
 },
 error: function(){
 openDialog('Datei nicht gefunden', file_in + " konnte nicht gefunden werden.\n<br />Bitte wende dich an einen Troubleshooter oder Teamleader!");
 }
});
return file_out;
};

that's that you knew how my Array is made... anyway with this i have an Array[rows][cols] to work with now i have in array[rows][14] a price which i want to compare i load one line which is the existing produkt (1d Array) and my 2d array

 function PackAusfiltern (arrzeile, arr) {
var Eingabearray = arr;
var Ausgabearray = "";
var BestandPreis = arrzeile[14];
BestandPreis = BestandPreis.replace(/,円/g, '.');
BestandPreis = parseFloat(BestandPreis);
//Here i get the Price of the existing Package which i want to compare

And now to my Actual Problem: I want to literate throug every Row, get the Value of column 14 and convert it to a number (some numbers are stored like "39,90" so i need to change the "," to ".")

i get here always an Error in line:

 var zwischenspeicher = Eingabearray[i][14]+""; 

it Says something like "for the property '14' is no value get able" (german IE 9...) Here is the for loop which should get the value, make it a number, compare it an delete elements where already the second line brings the error:

for (var i=0, j=Eingabearray.length; i<j; i++) {
 var zwischenspeicher = Eingabearray[i][14]+"";
 zwischenspeicher = zwischenspeicher.split(',').join('.');
 zwischenspeicher = parseFloat(zwischenspeicher);
 Eingabearray[i][14] = zwischenspeicher;
 if ((BestandPreis <= Eingabearray[i][14]) && Eingabearray[i][16] == 1)
 {
 var löschenPO = Eingabearray.indexOf(Eingabearray[i][17]); //find other pack code
 var löschenindex = Eingabearray.indexOf(löschenPO); // search other pack
 Eingabearray = Eingabearray.splice(löschenindex, 1); // delete other pack
 }
 };

just for information:

for (var i=0, j=Eingabearray.length; i<j; i++) {
 alert(Eingabearray[i][14]); //= '39.90'

and

type(Eingabearray[i][14]); //= [object Number]
 function type(obj){
alert(Object.prototype.toString.call(obj)); 
 }

hopefully you get my bad English and the formatting works so you can tell me what stupid mistake i made^^ all the best and marry Christmas

lang-js

AltStyle によって変換されたページ (->オリジナル) /