I have this section of code:
for (let i = 0; i < items.length; i++) {
//trim address to make sure there are no trailing whitespaces
const address = items[i].address.trim();
const token_uri = `${TOKEN_BASE_URI}/${tokenId}.json`;
Every time I run it I get the error:
TypeError: Cannot read properties of undefined (reading 'trim')
Could someone please tell me how to fix this, tia.
I tried adding various code snippets, defining the relevant const as a string, or as an empty string but nothing works. I don't know if I'm doing all the wrong things or I've done the right thing but the wrong way, but nothing has worked.
Related
I am trying to add a note using Add Note Button but it is throwing an exception. I handled the error using try...catch block but the note written in Add Note Button is not added and printing null on console.
JSBin for my project:
This piece:
if(notes =='')
{
notesObj = [];
}
else{
notesObj = JSON.parse(notes);
}
is the problem. If there's nothing in the local storage, notes will be null, which means notesObj == '' will be false, and the code will break. You need to change the test so it detects null (and other falsy values) as such:
if(!notes)
{
notesObj = [];
}
else{
notesObj = JSON.parse(notes);
}
There's another problem. This line:
localStorage.setItem('notes', JSON.stringify(notes));
makes no sense. You're setting the item notes in the local storage as the converted json of the notes variable, which is already a JSON string, so it'll fail horribly. What you really want to do is stringify the notesObj variable, which is the array with the actual notes. Change that line to:
localStorage.setItem('notes', JSON.stringify(notesObj));
And that's it. Make those changes and your code will work.
I made this account to ask this question because researching strings and testing a whole ton of different things ended up with nothing working. You should be able to see what I am trying to do with this code piece here that is not working for me. If I hard type out "Level1" instead of "Level[i]" everything works fine.
for (var i = 0; i<=100; i++)
{
if (levelOn == i)
{
var Lv:Level[i] = new Level[i];
addChild(Lv)
}
}
I have 100 level files labeled "level1", "level2", etc in the project folder. I am trying to access a certain level via using a forloop to add a certain level to the screen (levelOn = 56 means the compiler would add the class "Level56" to the screen.)
I think I have the right idea but I cannot get it to work, all I get is this error
Line 24 1086: Syntax error: expecting semicolon before leftbracket.
If someone has a more efficient way of accessing a "level" in a application (where it has the same base class but minor differences) please send me in the right direction.
Thanks!!!!!
Try this:
var i:int;
var Lv:Level[i] = new Level[i];
addChild(Lv)
for (i=0; i<100; i++){
if(LevelOn=i)
}
i have just started angular2, and got a problem. I am not able to iterate a json document in angular2.data is coming from backend i tried many ways, also used elipses (?) operator but not working for me. Please help
i want to print name under area array
in your .ts code, try the following:
ngOnInit() {
for(let i = 0; i < this.country.length; i++) {
for(let n = 0; n < this.country[i].area.length; n++) {
console.log(this.country[i].area[n].name);
}
}
}
You should get a list of all the names in the console
First get the json as a string; then simply call JSON.parse(myJsonString) and you have your json-object
If you meant anything else please clarify, as I (and obviously others too) don't find your question formualted 100% clearly (for example, add some code or what you have tried before)
I have some simple code:
var timer = Observable.Timer(TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(1)).Timestamp();
//timer.Subscribe(x => timerTb.Text = x.Value.ToString());
timer.Subscribe(x => Debug.WriteLine(x.Value));
And a textbox on the view called timerTb. I am trying to get the commented out line to work without it shouting about marshalling issues.
From what i can find out i should be using timer.ObserveOnDispatcher().Subscribe(...
But i do not have access to this method, nor do i have access to the CoreDispatcherScheduler dispite referencing "System.Reactive.Linq;"
I am running RX 2.0.20304.0
Any ideas?
I managed to get it working.
Silly rookie mistake CoreDispatcherScheduler was in : System.Reactive.Windows.Threading
Once i referenced that i got ObserveOnDispatcher() and this worked:
var timer = Observable.Timer(TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(1)).Timestamp();
timer.ObserveOnDispatcher().Subscribe(x => timerTb.Text = x.Value.ToString());
Put your timer on the UI thread:
Observable.Timer(TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(1), CoreDispatcherScheduler.Instance)
.Timestamp();
After making a change to some Google Maps code, I started getting the following error whenever I attempt to click-drag the map:
Uncaught TypeError: Object # has no method 'setCapture'
Google turned up no results for this error, so I though I'd create this question.
Can you show your code??
Recently I'm having an error likely yours. I'm doing this, in my javascript code:
var components = $(".comp-div");
for ( var i = 0; i <= components .size(); i++) {
components[i].css("width"));
}
When you use [] to access an item in a jQuery array, you get the DOM element not a jQuery object, probably you are doing this or something like, so it doesn't have any jQuery methods or any google-maps method.
I changed to use .eq() function, see next example:
var components = $(".comp-div");
for ( var i = 0; i <= components .size(); i++) {
components.eq(i).css("width"));
}