I'm trying to remove an element from an array. For some reason this isn't working.
MyArray = ["Fus", "Ro", "Dah", "Blah"];
MyArray.splice[2,1];
trace(MyArray); // returns ["Fus", "Ro", "Dah", "Blah"], splice did nothing to the array.
I'm sure I've missed something completely obvious but I've searched multiple forums and they all say that code is correct, but it's somehow not functioning at all.
You should try MyArray.splice(2,1);
Note the brackets! splice() is a function so () has to be used.
Related
I am using _.findIndex which returns me an array, which needs to be pushed to array. How can I do this?
$scope.filtersRequested[_.findIndex( $scope.filtersRequested, {
'codeColumnName': $scope.refData[idx].codeColumnName
} )].filterCondition = strWhere;
If I understand correctly, you'd like to set filterCondition on a specific value. Since you use lodash, you'd better use _.set which is safe (i.e. does not fail if the first arg is undefined) and _.find (to get access to the relevant request). Hence, I'd suggest you do:
_.set(
_.find( $scope.filtersRequested, {'codeColumnName': $scope.refData[idx].codeColumnName} ) ,
'filterCondition', strWhere
);
If an element was found, the _.set will operate on it, otherwise, it will gracefully ignore it.
I tried to access the following value in an multidimensional array:
var temp = allSliderData[i]['slider_full'][j].path;
and it works fine, but the following not
var temp2 = allSliderData[i]['slider_thumbs'][j].285x255;
with the answer
"SyntaxError: identifier starts immediately after numeric literal"
I now tried escapings, array functions .. this message is good known in stackoverflow .. but still no luck.
Could anybody help out?
THANKS!!
Something like that won't work. You can't have a property named "2" there. What exactly do you want to do?
the idea is to take a word and sub out all specified letters for another letter.
Any help on how to make this kind of function work?
The last array_push is not being called because you're returning before. Change it to:
array_push($stepsinchain, $subed);
return $subed;
Since $subed is never stored in the $stepsinchain array, due to the return being before, you're not able to access previous alternations.
array_push is also slower and not recommended when entering one element in an array. Instead, use
$stepsinchain[] = $subed;
It is also much faster as documented at http://www.php.net/manual/en/function.array-push.php#Hcom83388
I am using the DevExpress 9.3 CheckedComboBoxEdit, and I need to get the collection of all checked items. It seems like this should be a simple task, but the closest thing I have found to a solution is something that says I can use:
CheckedComboBoxEdit.Properties.GetItems.GetCheckedValues()
Unfortunately, there is no GetCheckedValues method here. I have found the following:
CheckedComboBoxEdit.Properties.GetCheckedItems()
which returns an object, but I cannot find any reference on what I should cast the object as. I have also tried to iterate through the items, and check each one to see if it is checked, following the suggestion from here, but Items returns a collection of Strings, not CheckedListBoxItem, so I cannot test if they are checked.
What I want is a String collection of checked items; right now, I am okay to receive them as any type of collection, or even create the collection myself. I know there must be some very simple thing that I am overlooking, but I can't seem to find it.
SOLUTION
This is the solution that I came up with. I would prefer something more elegant; it seems like there should be a way to get the checked items, since this is what the control is for. Nevertheless, this seems to work:
Private Function GetChecked() As List(Of String)
Dim checked As New List(Of String)
Dim checkedString As String = CType(SitePickerControl.Properties.GetCheckedItems(), String)
If (checkedString.Length > 0) Then
checked.AddRange(checkedString.Split(New Char() {","c}))
End If
Return checked
End Function
If anyone can give me a proper solution, I would love to see it.
This is what I use:
var ids = (from CheckedListBoxItem item in checkedComboBoxEdit.Properties.Items
where item.CheckState == CheckState.Checked
select (int)item.Value).ToArray();
You can also make an extension method on CheckedListBoxItem which will return only checked items values.
(It's C#, not VB, but the concept is the same.)
I know this is an old post, but I thought I should pitch in anyway.
I'm not sure on when v9.3 was released, but there definitely is a GetCheckedValues() function now. It is described here:
https://documentation.devexpress.com/#WindowsForms/DevExpressXtraEditorsControlsCheckedListBoxItemCollection_GetCheckedValuestopic
and I also found it as the answer in one of their support cases (which is much older than this post) here:
https://www.devexpress.com/Support/Center/Question/Details/Q431364
So to get a list of all the selected values you need something like:
myCombo.Properties.GetItems().GetCheckedValues()
or to check if a specific value was selected:
if (myCombo.Properties.GetItems().GetCheckedValues().contains("myvalue"))
I hope this helps future searchers.
For VB.NET
Dim ids = (From item In checkedComboBoxEdit.Properties.Items Where item.CheckState = CheckState.Checked Select CInt(item.Value)).ToArray()
This is what I use:
var ids = (checkedComboBoxEdit1.Properties.Items.Where(m => m.CheckState == CheckState.Checked)).Select(m => m.Value).ToArray();
Here is the single line from one of my functions to test if any objects in my array have a given property with a matching value
Return ((From tag In DataCache.Tags Where (tag.FldTag = strtagname) Select tag).Count = 1)
WHERE....
DataCache.Tags is an array of custom objects
strtagname = "brazil"
and brazil is definitely a tag name stored within one of the custom objects in the array.
However the function continually returns false.
Can someone confirm to me that the above should or should not work.
and if it wont work can someone tell me the best way to test if any of the objects in the array contain a property with a specific value.
I suppose in summary I am looking for the equivalent of a SQL EXISTS statement.
Many thanks in hope.
Your code is currently checking whether the count is exactly one.
The equivalent of EXISTS in LINQ is Any. You want something like:
Return DataCache.Tags.Any(Function(tag) tag.FldTag = strtagname)
(Miraculously it looks like that syntax may be about right... it looks like the docs examples...)
Many Thanks for the response.
Your code did not work. Then I realised that I was comparing to an array value so it would be case sensitive.
However glad I asked the question, as I found a better way than mine.
Many thanks again !