611 questions
3
votes
2
answers
185
views
Using for-in loop to iterate localStorage returns spurious entries
I am trying to make a basic notes app using JS.
I am storing notes in localStorage, and I am trying to print those notes using for-in loop. It works mostly fine, but I don’t know why I am getting ...
-4
votes
3
answers
110
views
Are There Hidden Dangers in Using for...in in JavaScript? [closed]
I wrote the algorithm below and asked an AI to evaluate my solution.
//TESTS:
console.log(firstNonRepeatingCharacter('abacabaz')) //c
console.log(firstNonRepeatingCharacter('aabbccdeefgghijj')) //d
...
1
vote
1
answer
162
views
Why for...in with an object in typescript is typed as string
I hope this is not a silly question. Why when I use for (let property in myObject)... property is recognized by typescript as "string" instead of "keyof typeof myObject"? Is there ...
-2
votes
1
answer
41
views
Unexpected token, for in loop in react js
I'm new to React.
I know that comments should be received as an object, so I tried using a for...in loop to iterate over them. However, when I attempted to use the for...in loop, I encountered an ...
2
votes
4
answers
129
views
Why does a for-in loop over an array not iterate over its elements?
var myArray = new Array();
var increment = 0;
myArray.push('Tom Hanks', 'Pierce Brosnan', 'Will Smith', 'Richard Ayoade');
for (actor in myArray) {
console.log(actor + ' is my #' + increment + ' ...
8
votes
5
answers
5k
views
How to hide properties of an object?
I would like to make some properties of an object to be hidden and some to be visible on iteration. So I tried to use prototype but that's not working:
function Car(){}
Car.prototype.version = '1.0'...
1
vote
1
answer
240
views
ERROR : " Trailing closure passed to parameter of type 'Binding<MapFeature?>' that does not accept a closure
import SwiftUI
import MapKit
import CoreLocation
struct ContentView: View {
@State private var position: MapCameraPosition = .userLocation(fallback: .automatic)
@State private var hazards: [(...
2
votes
2
answers
325
views
Nested for..of iterate over first array Element
I have Data Structure like this
const array = [
[["first_name" , "First"], ["image" , "image"]],
[["email" , "email"]],
[["...
1
vote
3
answers
628
views
Does for ... in loop loop through a copy of a sequence?
I came across such statements as the following in Matt Neuburg's iOS 13 Programming Fundamentals with Swift:
When you cycle through a sequence with for...in, what you’re actually cycling through is a ...
11
votes
5
answers
9k
views
Adding a custom iterator to a javascript class
I'm trying to figure out how to add an itertor to a javascript class such that the class could be used in a for...in loop. Following the instructions from Mozilla doesn't produce the results they ...
0
votes
1
answer
41
views
Using "for in" over a string to find a character but then not able to use the variable to reference another value
Still learning JS and confused over this
The below code gives out undefined as output when it should be "v" - am I missing something or using for-in over a string is the issue
let s="...
0
votes
3
answers
149
views
Compile error on iterating through self in inherited generic collection
I'm new to Delphi but am experienced in C# an would normally think this is a pretty easy thing to do but am getting a
"E2430 for-in statement cannot operate on collection type 'Class reference'"
...
-3
votes
3
answers
148
views
How are objects passed into a for...in loop in JavaScript?
I'm new to JavaScript and am learning about for...in loops and objects right now. I'm practicing with the following example:
let spaceship = {
crew: {
captain: {
name: 'Lily',
...
5
votes
7
answers
28k
views
How to dynamically populate an array using a for in loop
To return an array set with a sequence of random numbers between 1 and 500 I tried to refactor a standard for loop for(var i = 0; i< 50; i++) and that worked but when I tried to do a refactor using ...
0
votes
3
answers
72
views
Why is this for... in loop not working when trying to loop keys nested inside objects?
I tried looping names of front-end developers nested inside of objects(refer to code) and when I printed it to console it says display is not defined.
var employees =
{
sales: {
...