angularjs - Extra newline characters in JavaScript arrays -


i working on program parses csv files , moves respective data different arrays make spreadsheet out of them. however, spreadsheet has blank rows 1 cell each. upon further inspection, have found these cells contain single newline character each. have filtered arrays not contain newline characters, yet problem still persists. doing in conjunction angularjs, , while doubt causing problem, did not have issue before implemented angular.

has had before? dynamic creation of newline characters shouldn't be.

here of code:

        headers = breaktext[0];         function isdefined(element, index, array){             return (element !== undefined || element !=='\n');             //i tried stop newlines here, did nothing         };           //new header file including desired titles; no undefines         $scope.clearheaders = headers.filter(isdefined);         $scope.clearpatients = [];         for(var i=1; i<breaktext.length; i++){             if breaktext[0] {                 $scope.clearpatients.push(breaktext[i].filter(isdefined));             }         }; 

breaktext 2d array containing undefined areas had deleted stuff. above code creating new header array , another, 2d array hold array of data each person, without undefined spaces. these arrays contain blanks "" data, nothing \n or \r\n.

here part of angularjs implementation:

$scope.columns = $scope.clearheaders; $scope.cells = {}; $scope.values = $scope.clearpatients.map(function(c,row){     return c.map(function(data){         return {             content: data,             color: $scope.makecolors(data)         };     }); }); 

we have tried using replace function replace \n '' , disallow return data if '' causes issues since of our initial data blank. not stop creation of new cell. have tried wrapping in such if(data !== '\n') changed nothing.

edit1:

you can see working live here, yet designed work small csv file can downloaded here. text below table after upload file shows each cell bound to, , if click , edit cells, can see content dynamically changing. clicking on cells between rows, can see contain newline character.

i tried creating new filter function, check newline in clearpatients array, , filter new array, sans-newline. new array called in table rather 1 newlines. yet threw many errors not determined of source.

edit2:

after mike p's answer , other input, determined best way fix problem swap line var alltextlines = $scope.csv.split(/\r\n|\n/); regex /\r?\n/

thanks help!

your problem doesn't has angularjs. you've got text data in $scope.csv , split off regular expression, , creates array of strings in alltextlines.

this array of strings has useless lines in (at idx 1, 3, , 4). you'll either want modify regex split expression or loop through array , remove stuff don't want.

you may want check out guy's csv array js code @ javascript code parse csv data

i can see spreadsheet code creating rows & cells these portions of alltextlines. remove , you're in business.

debug of code


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -