611 questions
-4
votes
3
answers
105
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
127
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
39
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 ...
1
vote
1
answer
224
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: [(...
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
71
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: {
...
-3
votes
3
answers
146
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',
...
0
votes
1
answer
87
views
Unable to bound lifetime in for each loop using str.lines() function
I'm new to rust and i'm building an implementation of the grep command to learn this language.
I'm trying to create a function to match the search query in a case insensitive way, but i'm having ...
0
votes
2
answers
94
views
A for loop inside a for loop not executing after the first run
I've a dataset of firms with year from 1960-1989 and month (1-12) that looks like this.
PERMNO.
Year
Month
10057
1960
1
10057
1960
2
10057
1960
3
10057
1960
4
10057
1960
5
10057
1960
6
10057
1960
7
...
0
votes
1
answer
45
views
I am just confused in how the forin loop in js is used and why do we use const keyword in it
I have a object named user where one of the properties is skills and im trying to find a user who have the maximum no. of skills.
let maximum = 0;
let name;
for (const user in users) {
const len = ...
0
votes
1
answer
892
views
ReferenceError: string is not defined
I try to do iteration on object on nodejs using for in, on my local it's working just fine. but when i deploy it to web service, it pass an error.
but when i tried on my local it work just fine
const ...
0
votes
3
answers
416
views
Several approaches to converting values to lowercase not working
As part of a practice challenge for a bootcamp, I've been asked to: 'Fix the jumbled string values - replace them all with versions that are all lowercase'
I've tried several approaches based on ...
0
votes
2
answers
250
views
Keyword Declaration
Asked to:
'Iterate through the staff nested inside the restaurant object, and add their names to the staffNames array.'
My solution keeps getting rejected with this error:
'Use a declaration keyword ...
1
vote
1
answer
52
views
Trying to understand For In Loops [duplicate]
something is bugging me at the moment about For In Loops. I understand how to use them but what I can't seem to get my head around is.. Well, in this example:
const tree = {
name: 'Oak',
...
2
votes
3
answers
348
views
(Swift) Confused between a return value of a for-in loop within a function, and a return value that comes after the loop (within the function))
I am confused with the following code.
func allTestsPassed(tests: [Bool]) -> Bool {
for test in tests {
if test == false {
return false
}
}
return true
}
If ...
1
vote
1
answer
958
views
What's actually happening in for...of vs. for...in loops, and why can they sometimes be interchangeable?
I am wondering what's going on behind the scenes in for...in vs. for...of loops in JavaScript. I accidentally switched them up on two similar instances, where one worked and one didn't, and I'm trying ...
0
votes
0
answers
34
views
Getting multiple element values using DOM query in for..in Loop
HI i am practicing resume creator app using JavaScript. i wanted to take all user inputs using gelements by id method in a loop.
when i am trying getting error of null regarding value property
without ...
0
votes
2
answers
197
views
Sum of some elements in an array
I wonder how do I get the sum of some elements in an array?
for example, here's my array and I only need to sum up the first 5 elements:
var num = [31, 28, 31, 30, 30, 31, 30, 31, 30, 29, 31, 31]
I ...
-1
votes
1
answer
105
views
for in loop over list (with +=) coding beginner
a = [1,2,3]
for num in a:
a = a + [num]
print(a)
>>>[1,2,3,1,2,3]
a = [1,2,3]
for num in a:
a += [num]
print(a)
>>>
The first code works as expected, so I assume the below ...
0
votes
1
answer
47
views
getting null in end of arr when looping with for in [duplicate]
Array.prototype.myMap = function(callback) {
const newArray = [];
// Only change code below this line
for(let i in this){
newArray.push(callback(this[i], i, this))
}
// Only change code ...
1
vote
2
answers
144
views
Capitalizing letters using for in range loop [closed]
I'm trying to solve a problem where a for in range loop goes over a sentence and capitalises every letter following a ".", a "!" and a "?" as well as the first letter of ...
0
votes
2
answers
109
views
How to get all maximum frequency characters in string?
I have a string and I want to retrieve all the characters with maximum occurring frequency. I have created a function that returns a single maximum frequency character in the string. But how to modify ...
1
vote
0
answers
98
views
Django variables inside for loop inside JS script inside Django HTML template to fill data grid
I'm trying to substitute tables with JS Data Grids in my templates by using https://www.ag-grid.com/javascript-data-grid/getting-started/ .
When I copy-paste the example from above website, the data ...
0
votes
1
answer
293
views
Bash JQ filter code not run properly between DO -> DONE (WINDOWS + GITBASH)
I am running a piece of JQ filter code. This is been run on a Windows Server 2016 with GIT BASH.
the code looks like the following:
(don't mind the echo's and echo $i, this is for verbose reasons)
...
1
vote
2
answers
172
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 ...
0
votes
1
answer
49
views
How to sort list of object by ISO8601
I've got a list of object which after looping I'm trying to sort the final list by given ISO8601 format favouriteDateTime: 2022-12-16T10:46:55.551Z. There are mutiple sorting method but which one to ...
0
votes
0
answers
48
views
TERRAFORM (0.12) - Nested For-In or other technique to augment an object in a map
I have a map that looks like this:
stuff = {
object-1 = {
id = "1"
main_value = "blue"
additional_in_values = ["red"]
...
1
vote
1
answer
773
views
TERRAFORM: Modify Values for ZipMap while Transforming Map to new Keys
I thought this would be easy :frowning:
Goal is to transform this map:
```
accounts = {
"acct-key-1" = {
"billingcode" = "sys"
"future-key" = "...
-1
votes
1
answer
113
views
Given a number m and k separated by a space print the numbers between m and k
print the numbers between this two numbers
let a=[5,7];
var temp=[];
for(var i=5;i<=8;i++){
`temp.push(i);`
}
console.log(temp);=> in this i got all elements[5,6,7,8] but i need only ...
0
votes
1
answer
162
views
Is there a real alternative to "for ... in Object" in Javascript? (For debugging purposes) [duplicate]
As the MDN website says "for...in is most practically used for debugging purposes", which I also am doing. Is there any other way to get the same results instead of using for ... in to get ...
1
vote
1
answer
72
views
How to make a function that takes a string and replace some letters with another symbols
For example, we can replace “a” or “A” with @ and get “с@t” instead of “cat”. Letters to replace: a - @; i - 1; s - $; o - 0; t - +
Using a for-in or forEach() methods.
I used this option but it's ...
0
votes
3
answers
1k
views
Is it possible to replace elements of a list with a "for in" iteration in Python?
I'm trying to iterate over a list and change its values with a "for in" loop:
example_string = "This is a string."
for char in example_string :
char = 'r'
example_list = list(...
0
votes
2
answers
60
views
Print numbered list in swift
I am trying to print out a set of students in a class in a numbered list.
Here's the code I have
var spanish101: Set = ["Angela", "Declan", "Aldany", "Alex", &...
0
votes
4
answers
940
views
Finding the first positive number in the array
I want to show the first positive number in the array in the console blog, but according to my code, it displays the second one, which is 6. Please provide an answer to my problem and give an explain ...
0
votes
1
answer
90
views
Checking for Duplicates Using For-In Loop
I'm doing a codewars challenge that checks if Sudoku grid is valid.
https://www.codewars.com/kata/529bf0e9bdf7657179000008/train/javascript
It returns false if there are duplicate values in 1) ...
-2
votes
1
answer
114
views
Is using a numeric for loop with an array of keys faster than iterating over an object with a for-in loop in JavaScript?
Please note: This question is purely hypothetical and for learning purposes. I do not plan on making unnecessary micro-optimizations.
From research that I've done, it seems that using for-in loops are ...
1
vote
3
answers
637
views
How to get sum of transaction from an array of objects
I'm trying to return the sum of all transactions but the program isn't returning the sum
question
Define a function, totalTransactions, that takes an array of objects called transactions.
...
0
votes
0
answers
774
views
How to set a value from body request to existing object with typescript? ts(2322)
Sending put http call with express js. While using typescript and trying to iterate through the object,
I'm getting an error "Type 'any' is not assignable to type 'never'"
let i: keyof ...
-1
votes
1
answer
93
views
how to restart a for in loop iteration in javascript
I need to restart the loop every time the if statement occurs so that the correct roman numeral conversion works
by pushing the key(roman numeral) of the iterator to counter,
and by subtracting the ...
0
votes
1
answer
94
views
for in loop JavaScript returning undefined [duplicate]
let obj = {
a:10,
b:20,
c:true,
d:null
}
for(let key in obj) {
//console.log(key);
//console.log(obj.key); //4 undefined
console.log(obj[key]) // 10 20 true null //work
}
why dot ...
0
votes
0
answers
49
views
What did Swift do to avoid that Collection was mutated while being enumerated? [duplicate]
In Swift , the following code works well
var arr = [1, 2,3 ,4, 5, 6]
for num in arr{
arr.removeAll { val in
return val == num
}
}
...
0
votes
2
answers
146
views
Can someone explain this for/in loop to me?
/*
Write each function according to the instructions.
When a function's parameters reference `cart`, it references an object that looks like the one that follows.
{
"Gold Round ...
-1
votes
1
answer
342
views
function mapCharAndSum(N,K,str)
Map Characters & Sum Ended
Description
You are given a number stored in a variable with the nameN
You are also, given a string, whose length is stored in a variable with the nameK, and the string ...
0
votes
1
answer
2k
views
object.key value is showing undefined in the for in loop?
as u can see below , obj.key outside the for in loop is working properly but why not in the for in loop ?
and obj[key] inside the for in loop is working properly , what`s the reason behind one is ...
-1
votes
1
answer
43
views
JS + HTML: Im trying to use the for in or the for each loop instead of the default for loop in my code. But i can`t get it working
**I want to set the background of all objects of the .false class back to the default color before i change the correct class to green **
let objects = document.querySelectorAll('.false'); ...
-1
votes
2
answers
53
views
Javascript using for...in loop with objects
Is anyone can help me to found this output.
Sample output:
['milk', 'bread', 'potato']
[20, 15, 10]
Here is the code.
var itemsToBuy = {
milk: {
quantity : 5,
price: 20
},
...
0
votes
2
answers
62
views
Problems with Optionals
I started learning Swift on my own from books and a tutorial from YouTube. And when I tried to repeat over the video, I got the error
"Thread 1: Fatal error: Unexpectedly found nil while ...
0
votes
1
answer
75
views
Can I access memory location and values ( pointers and reference ) for variables in a loop, in Python 3
my_num_1 = 10
my_num_2 = 20
# I want to assign value 5 to above two variables like this:
for num in [my_num_1, my_num_2]:
num = 5
That won't work. So is there a way to do something like this ...
0
votes
2
answers
6k
views
How to access object keys names in javascript
console.log(answerKey);
for(singleKey in answerKey){
}
answerKey is my object. Can anybody please tell that how can I access object key names and values.
Please see the screenshot (https://prnt....
0
votes
1
answer
375
views
How to use DispatchGroup to update UI only after for-in loop has completed
When a user taps a button, that triggers a lengthy function consisting of an API call and calculations.
@IBAction func buttonTapped(_ sender: Any) {
var itemIndex = 0
let ...