This question already has an answer here:
list items are not deleting properly (React)
(1 answer)
Closed 3 years ago.
onRemoveVariant(groupKey, questionKey, variantKey) {
const {questionGroups} = this.props;
questionGroups[groupKey].questions[questionKey].variants.splice(variantKey, 1);
this.props.updateQuestionnaire('questionGroups', questionGroups);
}
I have 5 variants and when i edit if i use delete variant first or any other variant, always only last variant get splice!
Why? how to use splice if splice by key doesnt work?
Img example
Find the index of that particular element in an array and then use that index in place of splice(variantKey,1) as splice(index,1)
Related
This question already has answers here:
Check if every element in one array is in a second array
(10 answers)
Closed 2 years ago.
I am trying to filter my entites by tags array, that can look like this:
const tags = ["tag1", "tag2"];
Every entity has property tags, that can have existing tags, for example:
["tag1", "tag2", "tag3"];
Or:
["tag1", "tag2"];
I need to compare if the tags array and the tags array of entity has the same values.
So far I have tried this code, but it returns an entity even if the two arrays dont have the same values (I'm guessing the includes() function is to blame).
tags.every((tag: any) => doc.tags.includes(tag));
Any ideas how can I check if the arrays have the same values?
Thank you in advance.
You can also compare the length as well
tags.every((tag: any) => doc.tags.includes(tag)) && tags.length === doc.tags.length;
This question already has answers here:
How to add items to a spinner in Android?
(11 answers)
Closed 2 years ago.
I have a spinner where the contents are from an Array in Strings.xml. However I would like to be able to let the user add items to the array. Can anyone help and let me know if there is a way to do this?
Many thanks
ArrayAdapter has a method add(object) as seen here: ArrayAdapter | Android Developer
For example:
fun addItem(item: T) {
arrayAdapter.add(item)
// Refreshes the view to reflect the changes applied to arrayAdapter
arrayAdapter.notifyDataSetChanged()
}
This question already has answers here:
Determine whether an array contains a value [duplicate]
(18 answers)
Closed 7 years ago.
I have array of name:
$scope.myArray with some values.
Now I want to check an Item is present in array or not,
If it is not present then I want to push that item into array and If that item is already in array then I don't want to push it.
Please tell me how to do this ?
if($scope.myArray.indexOf(item) === -1) {
$scope.myArray.push(item)
}
You can read about indexOf for more details. Also, checkout underscore js for some readily available functions.
This question already has answers here:
Javascript multiple email regexp validation
(7 answers)
Closed 7 years ago.
I need to split a value from a cell into separate array values. I am taking a list of emails from my spreadsheet and need to use the addCommenters() method.
Spreadsheets cell value: email1#email.com, email2#email.com, email3#email.com ... etc.
I need to split around the ", " properly to pass the array into addCommenters().
What is the programmatic way to do this?
If you get the value of that cell (using .getValue())
var emails = sheet.getRange(range_here).getValue()
and then apply the split() method
var commentersArray = emails.split(",")
you will have an array you can pass to the .addCommenters() method.
file.addCommenters(commentersArray);
This question already has answers here:
Naming Image using index of for loop in each iteration
(2 answers)
Closed 7 years ago.
I want to do this with a shorter operation. How can i do it? Thank you
data = [Test1;Test2;Test3;Test4;Test5;Test6;Test7;---- until-----;Test36];
You can solve this using eval, however the use of this function is usually not recommended:
eval(['data=[', sprintf('Test%d;',(1:36)),'];'])
Rather follow Dan's comment and don't create seperate matrices.
You can use the eval command to do this:
Test1=magic(5);
Test2=magic(5);
data=cell.empty(2,0);
for ii=1:2
data{ii} = eval(sprintf('Test%d', ii));
end