Answer the question
In order to leave comments, you need to log in
Array parsing and data processing in JS code. How to get past the error?
How to get past the error?
There is a task: removing from the array all lines that go above three consecutive lines at the end of which there are punctuation marks (punctuation marks are defined in the array )
There is a JS code for this (I gave it at the end of this topic). I process this array of text with code, but I get an error:
SyntaxError: Unexpected token Я in JSON at position 1
let text = `Я видел огненные знаки
Чудес, рожденных на заре
Я вышел — пламенные маки,
Сложить на горном алтаре.
Со мною утро в дымных ризах,
Кадило в голубую твердь,
И на уступах, на карнизах`;
let text = ;
let text = ;
var qqq = JSON.parse("[" + text + "]");
let str = qqq.split(',');
let text = ;
var qqq = JSON.parse("[" + text + "]");
let str = qqq.split(',');
const punct = ;
const numStrWithPunctEnd = 3;
const arr = str.split('\n');
const index = arr.findIndex(function(n, i, a) {
return this.every(m => punct.includes(a[i + m].slice(-1)));
}, [...Array(numStrWithPunctEnd).keys()]);
const result = index !== -1 ? arr.slice(index).join('\n') : str;
=result;
Answer the question
In order to leave comments, you need to log in
For the JS language, it is an array (An array is an object)For the JS language, an array and an object are two different things.
let text =
This creates an array with one element, which is also an array. Within this internal array, one element is the variable 1AA. And here there will be errors: there is no variable 1AA to put it in a subarray; A variable name cannot start with a number.I do parsing using JSON.parse converting the array to a string
JSON.parse
on the contrary, it turns the JSON string into an object. The string text
is not a JSON string and therefore this method throws an error.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question