Programming Language Comparison: Objects

Strings [StrJoin/String] Mathematics Operators and Symbols General (Control Flow/Debugging) Dates Objects New Features Timelines Sections: Any Methods Print New Loop Array Methods Map Methods Object Methods Range Methods Array.Map Examples Import/Include Tips Language-Specific Notes Note: UFL: Universal Function Library, a set of around 100-300 standard functions for all programming languages. Languages do not have to implement anything exactly to the UFL specification, it is a guide. See lower down for further details. Section: Any Methods UFL: Any.Type [object type: name only] AutoHotkey: Type(oObj) C++: typeid(oObj).name() [e.g. 'i' for an int][note: return values can be cryptic] C#: oObj.GetType().Name [also (for types, not variables): typeof() e.g. typeof(int)] Excel: TYPE(A1) Excel VBA: TypeName(oObj) [also: TypeOf operator (which works on objects, but not primitives)] Java: oObj.getClass().getSimpleName() [WARNING: doesn't work on primitives][also (for types, not variables): .class e.g. int.class] JavaScript: typeof oObj Kotlin: oObj::class.simpleName PHP: gettype($oObj) Python: type(oObj).__name__ Swift: String(describing:type(of:oObj)) UFL: Any.TypeFull [object type: full name] AutoHotkey: Object.Prototype.ToString.Call(oObj) C++: ___ [can use: typeid(oObj).name()] C#: oObj.GetType().FullName Excel: ___ Excel VBA: ___ Java: oObj.getClass().getName() [WARNING: doesn't work on primitives][also (for types, not variables): .class e.g. int.class][note: '[I'/'[D' for int/double arrays respectively] JavaScript: Object.prototype.toString.call(oObj) Kotlin: oObj::class.qualifiedName PHP: ___ [can use: gettype($oObj)][also (for objects): get_class($oObj)] Python: type(oObj) Swift: String(reflecting:type(of:oObj)) UFL: Any.IsObject [is the value an object (e.g. is object: array/map, e.g. not object: 'primitive'/'value'/int/float/string/bool/null) (definitions of a primitive/value/non-object vary)][e.g. for a custom print function, which 'to string' approach to use] AutoHotkey: vIsObj := IsObject(vVar) C++: ___ [can use: vIsObj = !std::is_fundamental<decltype(vVar)>::value && !std::is_same<decltype(vVar),std::string>::value][requires: #include <type_traits>] C#: ___ [can use: vIsObj = !vVar.GetType().IsPrimitive && !(vVar is string)] Excel: ___ Excel VBA: vIsObj = IsObject(vVar) Or IsArray(vVar) Java: ___ [can use (to check for non-primitive non-string): var vIsObj = !(Integer.class.isInstance(vVar)||Byte.class.isInstance(vVar)||Short.class.isInstance(vVar)||Long.class.isInstance(vVar)||Float.class.isInstance(vVar)||Double.class.isInstance(vVar)||Boolean.class.isInstance(vVar)||Character.class.isInstance(vVar)||((Object)vVar).getClass().equals(String.class))] JavaScript: vIsObj = (typeof vVar === "object") && (vVar !== null) Kotlin: ___ [can use (to check for non-primitive non-string): vIsObj = (vVar::class.javaPrimitiveType == null) && (vVar !is String)] PHP: $vIsObj = is_object($vVar) || is_array($vVar) Python: ___ [can use: vIsObj = not isinstance(vVar, str|int|float|None)][note: bool is a subclass of int (i.e. int covers int and bool), e.g. 'isinstance(True, int)' returns True] Swift: ___ [can use: vIsObj = !((vVar is String) || (vVar is Int) || (vVar is Float) || (vVar is Double) || (vVar is Bool))] UFL: Any.IsArray [e.g. for a custom print function (e.g. use string join on 1-dimensional arrays)] AutoHotkey: vVar is Array C++: std::is_array<decltype(vVar)>::value [requires: #include <type_traits>] C#: vVar is Array Excel: ___ Excel VBA: IsArray(vVar) Java: ((Object)vVar).getClass().isArray() JavaScript: Array.isArray(vVar) Kotlin: vVar::class.java.isArray PHP: is_array($vVar) [also ('keys consist of consecutive numbers from 0 to count($array)-1'): array_is_list($vVar)] Python: isinstance(vVar, list) Swift: vVar is Array<Any> UFL: Any.CopyRef [create reference][note: object of any type] AutoHotkey: oObjNew := oObj C++: &oObjNew = oObj [e.g. MyStruct &oObjNew = oObj][e.g. std::string (&oArrayNew)[] = oArray][e.g. std::map<std::string,std::string> &oMapNew = oMap][e.g. auto &oRangeNew = oRange][e.g. auto &oVecNew = oVec] C#: oObjNew = oObj Excel: ___ Excel VBA: Set oObjNew = oObj [note: this fails with Array objects, there is not a standard way to create a reference to an Array object] Java: oObjNew = oObj JavaScript: oObjNew = oObj Kotlin: oObjNew = oObj PHP: $oObjNew = $oObj [WARNING: for arrays, this copies the array, instead, do: $oArrayNew = &$oArray] Python: oObjNew = oObj Swift: oObjNew = oObj [WARNING: for value types (e.g. Array/Dictionary/Tuple/Struct/Enum), this copies the object] UFL: Any.DelRef [or Any.DeleteRef][delete object reference (and delete object if it's the last reference)][see also: VarDelete][note: object of any type] AutoHotkey: oObj := unset [note: in AHK v1: 'oObj := ""' and 'oObj := 0' were common] C++: delete oObj [also: delete[] oObj][note: 'delete'/'delete[]' must be used for variables created with 'new'][note: 'free' must be used for variables created with 'malloc'] C#: oObj = null Excel: ___ Excel VBA: Set oObj = Nothing [note: doesn't work with all types] Java: oObj = null JavaScript: oObj = null [also: oObj = undefined][also: void operator] Kotlin: oObj = null PHP: unset($oObj) [also: $oObj = null][note: unset() sets contents to null] Python: del oObj [also: oObj = None] Swift: oObj = nil Section: Print UFL: Array.Print [print the key-value pairs][tested on int/float/string arrays][see also: Array.Join] AutoHotkey: ___ C++: for (const auto& vValue : oArray) std::cout << vValue << "," [also (for array on the heap): for (const auto& vValue : std::views::counted(oArray, vSize)) std::cout << vValue << ","][requires (std::views::counted): #include <ranges>][also (for array on the heap): for (const auto& vValue : *(int(*)[vSize])oArray)][also (for array on the heap): for (const auto& vValue : *(int(*)[vSize])&oArray[0])] C#: Console.WriteLine("[" + String.Join(",", oArray) + "]") Excel: ___ Excel VBA: Debug.Print "[" & Join(oArray, ",") & "]" Java: System.out.println(java.util.Arrays.toString(oArray)) [also: System.out.println(java.util.Arrays.deepToString(oArray))][note: deepToString() worked on: String[]/int[][]/double[][]/String[][], failed on: int[]/double[]] JavaScript: console.log(oArray) [also: alert([...oArray.entries()].join("\n"))] Kotlin: println(oArray.toList()) PHP: var_export($oArray) [also: var_dump($oArray)] Python: print(oList) Swift: print(oArray) UFL: Map.Print [print the key-value pairs] AutoHotkey: ___ C++: for (const auto& [vKey, vValue] : oMap) std::cout << vKey << ":" << vValue << "\n" C#: Console.WriteLine(String.Join("\n", oDict)) [also: Console.WriteLine(String.Join("\n", oDict.Select(e=>$"{e.Key}:{e.Value}")))][requires (Select): using System.Linq] Excel: ___ Excel VBA: ___ Java: System.out.println(oMap) JavaScript: console.log(oMap) [also: alert([...oMap.entries()].join("\n"))] Kotlin: println(oMap) PHP: var_export($oMap) [also: var_dump($oMap)] Python: print(oDict) Swift: print(oDict) UFL: Object.Print [print the property-value pairs] AutoHotkey: ___ C++: ___ C#: Console.WriteLine(String.Join("\n", ((IDictionary<string,object>)oObj))) Excel: ___ Excel VBA: ___ Java: for (Field f : oObj.getClass().getFields()) {try {System.out.println(f.getName() + " " + f.get(oObj));} catch (Exception e) {}} [requires: import java.lang.reflect.Field][e.g. works with int/float/string values] JavaScript: console.log(oObj) [also: alert(JSON.stringify(oObj, null, 4))][also: alert([...Object.entries(oObj)].join("\n"))] Kotlin: ___ PHP: var_export($oObj) [also: var_dump($oObj)] Python: print(oObj) Swift: print(oObj) UFL: Range.Print [print start/end/step (or print the values)] AutoHotkey: ___ C++: for (const auto& vValue : oRange) std::cout << vValue << "," C#: Console.WriteLine("[" + String.Join(",", oRange) + "]") Excel: ___ Excel VBA: ___ Java: System.out.println(java.util.Arrays.toString(oRange.toArray())) [WARNING: terminal operation, makes oRange unusable] JavaScript: ___ Kotlin: println(oRange) PHP: var_export($oRange) [also: var_dump($oRange)][note: range() returns an array] Python: print(oRange) Swift: print(oRange) Section: New UFL: Array.NewEmpty [or Array.NewBasic][create an empty array] AutoHotkey: oArray := [] [type: Array][note: 1-based] C++: int oArray[] = {} [type: e.g. A0_i / A0_d / (mangled) (int/double/std::string arrays respectively)][also: std::vector<int> oVec] C#: int[] oArray = {} [type: e.g. Int32[] / Double[] / String[] (int/double/string arrays respectively)][also (C# 12 onwards): int[] oArray = []][also: var oList = new List<int>()][requires (List): using System.Collections.Generic] Excel: ___ Excel VBA: oArray = Array() [type: Variant()][note: 0-based by default, can specify the start index][note: an alternative class: Set oArray = CreateObject("System.Collections.ArrayList")] Java: int[] oArray = {} [type: e.g. int[] / double[] / String[] (int/double/string arrays respectively)][also: var oList = new ArrayList<int>()] JavaScript: oArray = [] [type: Array] Kotlin: oArray = arrayOf() [type: Array] PHP: $oArray = [] [type: array][also: array()][note: an associative array that also has linear array functionality][note: 0-based by default, can specify the start index] Python: oList = [] [type: list] Swift: oArray = [] [type: e.g. Array<Int> / Array<Double> / Array<String> (Int/Double/String arrays respectively)] UFL: (Array.NewDemoInt) [create an array containing 1, 2, 3] AutoHotkey: oArray := [1, 2, 3] C++: int oArray[] = {1, 2, 3} [also: std::vector<int> oVec = {1, 2, 3}] C#: int[] oArray = {1, 2, 3} [also: var oList = new List<int>{1, 2, 3}] Excel: ___ Excel VBA: oArray = Array(1, 2, 3) Java: int[] oArray = {1, 2, 3} [also (fixed size): List<Integer> oList = Arrays.asList(1, 2, 3)][also (read-only): var oList = List.of(1, 2, 3)] JavaScript: oArray = [1, 2, 3] Kotlin: oArray = arrayOf(1, 2, 3) PHP: $oArray = [1, 2, 3] Python: oList = [1, 2, 3] Swift: oArray = [1, 2, 3] [e.g. empty array: oArray = [Int]()] UFL: (Array.NewDemoStr) [create an array containing a, b, c] AutoHotkey: oArray := ["a", "b", "c"] C++: std::string oArray[] = {"a", "b", "c"} [also: std::vector<std::string> oVec = {"a", "b", "c"}] C#: string[] oArray = {"a", "b", "c"} [note: 'String[]' also works][also: var oList = new List<string>{"a", "b", "c"}] Excel: ___ Excel VBA: oArray = Array("a", "b", "c") Java: String[] oArray = {"a", "b", "c"} [note: 'string[]' doesn't work][also (fixed size): List<String> oList = Arrays.asList("a", "b", "c")][also (read-only): var oList = List.of("a", "b", "c")] JavaScript: oArray = ["a", "b", "c"] Kotlin: oArray = arrayOf("a", "b", "c") PHP: $oArray = ["a", "b", "c"] Python: oList = ["a", "b", "c"] Swift: oArray = ["a", "b", "c"] [e.g. empty array: oArray = [String]()] UFL: (Array.NewDemoStrEntries) [or Array.NewDemoStrArrayOfArrays][array of arrays e.g. entries (key-value pairs)] AutoHotkey: oEntries := [["k1","v1"], ["k2","v2"], ["k3","v3"]] C++: std::string oEntries[][2] = {{"k1","v1"}, {"k2","v2"}, {"k3","v3"}} [also: std::vector<std::vector<std::string>> oEntries = {{"k1","v1"}, {"k2","v2"}, {"k3","v3"}}] C#: string[][] oEntries = {new[]{"k1","v1"}, new[]{"k2","v2"}, new[]{"k3","v3"}} Excel: ___ Excel VBA: oEntries = Array(Array("k1", "v1"), Array("k2", "v2"), Array("k3", "v3")) Java: String[][] oEntries = {{"k1","v1"}, {"k2","v2"}, {"k3","v3"}} JavaScript: oEntries = [["k1","v1"], ["k2","v2"], ["k3","v3"]] Kotlin: oEntries = arrayOf(arrayOf("k1","v1"), arrayOf("k2","v2"), arrayOf("k3","v3")) PHP: $oEntries = [["k1","v1"], ["k2","v2"], ["k3","v3"]] Python: oEntries = [["k1","v1"], ["k2","v2"], ["k3","v3"]] Swift: oEntries = [["k1","v1"], ["k2","v2"], ["k3","v3"]] UFL: (Array.NewDemoSize) [create an array of size n, the values don't matter][see also: Array.Rept/Range.ToArray] AutoHotkey: (oArray := []).Length := vCount [note: 'no value'-initialised][also (space-initialised, i.e. 1-char string, Chr(32)): StrSplit(Format("{:" vCount "}", ""))] C++: int* oArray = new int[vCount] [note: zero-initialised][also ('random'-value-initialised, replace '123' with the necessary size): int oArray[123]][also (zero-initialised): int oArray[123] = {}][also (zero-initialised): std::vector<int> oVec(vCount)] C#: int[] oArray = new int[vCount] [also: var oList = Enumerable.Repeat(0, vCount).ToList()][note: both zero-initialised] Excel: ___ Excel VBA: ReDim oArray(0 To vCount - 1) [note: empty-initialised][note (zero-initialised): ReDim oArrayX(0 To vCount - 1) As Integer] Java: int[] oArray = new int[vCount] [note: zero-initialised] JavaScript: oArray = Array(vCount) [note: empty-initialised (elided)][also (zero-initialised): oArray = Array(vCount).fill(0)] Kotlin: oArray = IntArray(vCount) [note: zero-initialised] PHP: $oArray = range(0, $vCount-1) [also (zero-initialised): $oArray = array_fill(0, $vCount, 0)] Python: oArray = [0] * vCount [note: zero-initialised] Swift: oArray = Array(repeating:0, count:vCount) [note: zero-initialised] UFL: Map.NewEmpty [or Map.NewBasic][create an empty map] AutoHotkey: oMap := Map() [type: Map][note: key order alphabetical (case sensitive)][note: AHK v1: key order alphabetical (case *insensitive*)] C++: std::map<std::string,std::string> oMap [requires: #include <map>][note: key order alphabetical (case sensitive)][type: (mangled) (e.g. <int,int>/<double,double>/<std::string,std::string> maps)] C#: var oDict = new Dictionary<string,string> {} [requires: using System.Collections.Generic][type: Dictionary`2 (e.g. <int,int>/<double,double>/<string,string> dictionaries)] Excel: ___ Excel VBA: Set oColl = New Collection [also: Dim oColl As New Collection][type: Collection][note: 1-based][note: an alternative class: Set oDict = CreateObject("Scripting.Dictionary")][WARNING: Excel Collection keys can't be retrieved via a loop, so store them in a separate array/collection] Java: LinkedHashMap<String,String> oMap = new LinkedHashMap() [requires: import java.util.*][type: LinkedHashMap] JavaScript: oMap = new Map() [type: Map] Kotlin: oMap = mutableMapOf<String, String>() [also: mapOf()][type (mutableMapOf): LinkedHashMap][type (mapOf): SingletonMap] PHP: $oMap = [] [type: array][also: array()][note: an associative array that also has linear array functions] Python: oDict = {} [type: dict] Swift: oDict = [String: String]() [type: e.g. Dictionary<String,String>][WARNING: 'random' key order, not insertion order][can use (insertion order, but allows duplicates) e.g. oDict: KeyValuePairs = ["k1":"v1", "k2":"v2", "k3":"v3"]] UFL: (Map.NewDemoStr) [initialise a map/dictionary with 3 items] AutoHotkey: oMap := Map("k1","v1", "k2","v2", "k3","v3") C++: std::map<std::string,std::string> oMap = {{"k1","v1"},{"k2","v2"},{"k3","v3"}} C#: var oDict = new Dictionary<string,string> {{"k1","v1"},{"k2","v2"},{"k3","v3"}} Excel: ___ Excel VBA: ___ [e.g. Set oColl = New Collection][e.g. Call oColl.Add("v1", "k1")] Java: LinkedHashMap<String,String> oMap = Arrays.stream(oEntries).collect(LinkedHashMap::new, (a,e)->a.put(e[0],e[1]), Map::putAll) [also: for (String[] e : oEntries) oMap.put(e[0], e[1])][also (random order, not insertion order): HashMap<String,String> oMap = new HashMap(Map.of("k1","v1", "k2","v2", "k3","v3"))][e.g. String[][] oEntries = {{"k1","v1"},{"k2","v2"},{"k3","v3"}}][requires: import java.util.*] JavaScript: oMap = new Map([["k1","v1"], ["k2","v2"], ["k3","v3"]]) Kotlin: oMap = mutableMapOf("k1" to "v1", "k2" to "v2", "k3" to "v3") [also: mapOf()] PHP: $oMap = ["k1"=>"v1", "k2"=>"v2", "k3"=>"v3"] Python: oDict = {"k1":"v1", "k2":"v2", "k3":"v3"} Swift: oDict = ["k1":"v1", "k2":"v2", "k3":"v3"] UFL: (Map.Order) [insertion order, alphabetical order, 'random' order (unordered)] AutoHotkey: ___ [key order: Map: alphabetical (case sensitive)][note: AHK v1: key order: alphabetical (case *insensitive*)][can use (insertion order map): Scripting.Dictionary] C++: ___ [key order: std::map<std::string,std::string>: alphabetical (case sensitive)] C#: ___ [key order: Dictionary<string,string>: insertion] Excel: ___ Excel VBA: ___ Java: ___ [key order: LinkedHashMap<String,String>: insertion (or optionally access)][WARNING: key order: HashMap<String,String>: random] JavaScript: ___ [key order: Map: insertion] Kotlin: ___ [key order: mutableMapOf: insertion] PHP: ___ [key order: []: insertion] Python: ___ [key order: {}: insertion] Swift: ___ [WARNING: key order: [String: String]: random] UFL: Object.NewEmpty [or Object.NewBasic][create an empty JavaScript-like object (dot notation, modify/add properties) for storing properties][can modify and add properties, unless stated] AutoHotkey: oObj := {} [type: Object] C++: ___ [can use: 'struct MyStruct' and a function body][afterwards: MyStruct oObj][note: can't add properties][type: (custom)] C#: dynamic oObj = new ExpandoObject() [note: can modify/add properties][also (anonymous type: read-only: can't add/modify properties): e.g. var oObj = new {p1="v1", p2="v2", p3="v3"}][requires (ExpandoObject): using System.Dynamic][type: ExpandoObject][type (anonymous type): e.g. <>f__AnonymousType0`3] Excel: ___ Excel VBA: ___ Java: ___ [can use: 'public static class MyClass' and a function body with some 'public' properties][afterwards: MyClass oObj = new MyClass()][note: can't add properties][type: (custom)] JavaScript: oObj = {} [type: Object] Kotlin: ___ [can use: 'data class MyDataClass' with a function body, then 'oObj = MyDataClass()'][also (for a singleton): 'oSingleton = object' with a function body, then 'oSingleton.MyProp'][note (for both): can't add properties][type (data class): simple name: (custom), qualified name: null][type (singleton): null] PHP: $oObj = new stdClass() [note: member access: uses '->', not '.'] Python: oObj = SimpleNamespace() [type: SimpleNamespace][note: oObj.__dict__ returns a dict object][requires: from types import SimpleNamespace] Swift: ___ [can use: 'struct MyStruct' then 'oObj = MyStruct()'][note: can't add properties][type: (custom)] UFL: (Object.NewDemoStr) [initialise a JavaScript-like object with 3 items (or the nearest equivalent)] AutoHotkey: oObj := {p1:"v1", p2:"v2", p3:"v3"} C++: struct MyStruct {std::string p1="v1"; std::string p2="v2"; std::string p3="v3";} [afterwards: MyStruct oObj][note: can't add properties] C#: foreach (var oEntry in (new Dictionary<string,object>{{"p1","v1"},{"p2","v2"},{"p3","v3"}})) ((IDictionary<string,object>)oObj).Add(oEntry) [beforehand: dynamic oObj = new ExpandoObject()][also (anonymous type: read-only: can't add/modify properties): var oObj = new {p1="v1", p2="v2", p3="v3"}][requires (ExpandoObject): using System.Dynamic] Excel: ___ Excel VBA: ___ Java: public static class MyClass {public String p1="v1", p2="v2", p3="v3";} [afterwards: MyClass oObj = new MyClass()][note: can't add properties] JavaScript: oObj = {p1:"v1", p2:"v2", p3:"v3"} Kotlin: data class MyDataClass(var dummy:String="") {var p1="v1"; var p2="v2"; var p3="v3"} [afterwards: oObj = MyDataClass()][note: can't add properties] PHP: $oObj = (object)["p1"=>"v1", "p2"=>"v2", "p3"=>"v3"] [type: object (class: stdClass)] Python: oObj = SimpleNamespace(**{"p1":"v1", "p2":"v2", "p3":"v3"}) [requires: from types import SimpleNamespace] Swift: struct MyStruct {var p1="v1"; var p2="v2"; var p3="v3"} [afterwards: oObj = MyStruct()][note: can't add properties] UFL: (Object.Order) [insertion order, alphabetical order, 'random' order (unordered)] AutoHotkey: ___ [key order: {}: alphabetical (case *insensitive*) (AHK v1: also case insensitive)] C++: ___ C#: ___ [key order: ExpandoObject (and anonymous type): insertion] Excel: ___ Excel VBA: ___ Java: ___ [key order: MyClass: insertion] JavaScript: ___ [key order: {}: insertion] Kotlin: ___ PHP: ___ [key order: stdClass: insertion] Python: ___ [key order: SimpleNamespace: insertion] Swift: ___ [key order: Struct: insertion] UFL: Range.New [or Range.NewBasic1][inclusive end][note: using 1 to 3 inclusive as an example] AutoHotkey: ___ C++: ___ [can use: auto oRange = std::views::iota(1, 3+1)][requires: #include <ranges>][type: NSt3__26ranges9iota_viewIiiEE] C#: ___ [can use: var oRange = Enumerable.Range(1, 3)][type: RangeIterator][WARNING: 2nd param is count, not end, e.g. inclusive end: Enumerable.Range(vStart, vEnd-vStart+1)][note (generates a Range, not RangeIterator): 1..3][requires (Enumerable.Range): using System.Linq] Excel: ___ Excel VBA: ___ Java: var oRange = IntStream.rangeClosed(1, 3) [WARNING: an IntStream can only be iterated over once, it cannot be reused][type: Head (full: java.util.stream.IntPipeline$Head)] JavaScript: ___ [can use (inclusive end, step 1): oArray = Array(vEnd-vStart+1).fill().map((v,k)=>k+vStart)][also: oArray = [...Array(vEnd-vStart+1).keys()].map(v=>v+vStart)] Kotlin: oRange = 1..3 [type: IntRange] PHP: $oRange = range(1, 3) [type: array][WARNING: returns an array, not an object that generates values on-the-fly] Python: ___ [can use: range(1, 3+1)] Swift: oRange = 1...3 [type: ClosedRange<Int>][also (inclusive end): stride(from:vStart, through:vEnd, by:vStep)] UFL: (Range.NewUntil) [or Range.NewBasic2][exclusive end][note: using 1 to 3 inclusive as an example] AutoHotkey: ___ C++: auto oRange = std::views::iota(1, 4) [requires: #include <ranges>][type: NSt3__26ranges9iota_viewIiiEE] C#: ___ [can use: var oRange = Enumerable.Range(1, 4-1)][type: RangeIterator][WARNING: 2nd param is count, not end, e.g. exclusive end: Enumerable.Range(vStart, vEnd-vStart)][note (generates a Range, not RangeIterator): 1..^4][requires: using System.Linq] Excel: ___ Excel VBA: ___ Java: var oRange = IntStream.range(1, 4) [WARNING: an IntStream can only be iterated over once, it cannot be reused][type: Head (full: java.util.stream.IntPipeline$Head)] JavaScript: ___ [can use (exclusive end, step 1): oArray = Array(vEnd-vStart).fill().map((v,k)=>k+vStart)] Kotlin: oRange = 1..<4 [type: IntRange] PHP: ___ [can use: range(1, 4-1)] Python: oRange = range(1, 4) [type: range] Swift: oRange = 1..<4 [type: Range<Int>][also (exclusive end): stride(from:vStart, to:vEnd, by:vStep)] Section: Loop UFL: (Array.LoopDemoKeyValue) [loop through the items of an array, get key-value pairs one-by-one] AutoHotkey: for vKey, vValue in oArray C++: ___ [can use: for (const auto& vValue : oArray)][note (won't work on all object types): vKey = &vValue-&oArray[0]][also: for (int i=0; i<sizeof(oArray)/sizeof(oArray[0]); i++)][also: for (int i=0; i<oVec.size(); i++)] C#: foreach (var oEntry in oArray.Select((v,k)=>new{Key=k,Value=v})) [also: foreach (var oEntry in oArray.Select((Value,Key)=>new{Key,Value}))][note (both): oEntry.Key, oEntry.Value][requires: using System.Linq] Excel: ___ Excel VBA: ___ [can use: For i = LBound(oArray) To UBound(oArray)][note: vValue = oArray(i)][also (for collections): For Each vValue In oColl][afterwards (for both): Next] Java: ___ [can use: for (int i=0; i<oArray.length; i++)][note: vValue = oArray[i]] JavaScript: for (const [vKey, vValue] of oArray.entries()) [also (ES6): oArray.forEach(function(vValue, vKey)][also (unspecified order): for (var vKey in oArray)] Kotlin: for ((vKey, vValue) in oArray.withIndex()) PHP: foreach ($oArray as $vKey=>$vValue) Python: for vKey, vValue in enumerate(oList): Swift: for (vKey, vValue) in oArray.enumerated() UFL: (Array.LoopDemoValue) [loop through the items of an array, get values one-by-one] AutoHotkey: for _, vValue in oArray [also (AHK v2 onwards): for vValue in oArray] C++: for (const auto& vValue : oArray) [also: for (const auto& vValue : oVec)] C#: foreach (var vValue in oArray) Excel: ___ Excel VBA: ___ [can use: For i = LBound(oArray) To UBound(oArray)][note: vValue = oArray(i)][also (for collections): For Each vValue In oColl][afterwards (for both): Next] Java: for (var vValue : oArray) JavaScript: for (const vValue of oArray) [also (ES6): oArray.forEach(function(vValue)] Kotlin: for (vValue in oArray) PHP: foreach ($oArray as $vValue) Python: for vValue in oList: Swift: for vValue in oArray UFL: (Map.LoopDemo) [loop through the items of a map/dictionary, get key-value pairs one-by-one] AutoHotkey: for vKey, vValue in oMap C++: for (const auto& [vKey, vValue] : oMap) C#: foreach (var oEntry in oDict) [also: foreach (KeyValuePair<string,string> oEntry in oDict)][note: oEntry.Key, oEntry.Value][requires: using System.Collections.Generic] Excel: ___ Excel VBA: For Each vValue In oColl [afterwards: Next][WARNING: for a Collection object, can loop through values, but not keys, must store a list of keys manually] Java: for (var oEntry : oMap.entrySet()) [note: oEntry.getKey(), oEntry.getValue()] JavaScript: for (const [vKey, vValue] of oMap) [also (ES6): oMap.forEach(function(vValue, vKey)] Kotlin: for ((vKey, vValue) in oMap) PHP: foreach ($oMap as $vKey=>$vValue) Python: for vKey, vValue in oDict.items(): Swift: for (vKey, vValue) in oDict UFL: (Object.LoopDemo) [loop through the items of an object, get property-value pairs one-by-one] AutoHotkey: for vProp, vValue in oObj.OwnProps() C++: ___ C#: foreach (var oEntry in (IDictionary<string,object>)oObj) [note: oEntry.Key, oEntry.Value][also (for anonymous type): foreach (var oEntry in oObj.GetType().GetProperties())][note (for anonymous type): oEntry.Name, oEntry.GetValue(oObj)] Excel: ___ Excel VBA: ___ Java: for (Field oField : oObj.getClass().getFields()) [note: property/value: oField.getName(), oField.get(oObj)][note: get()/set() must be within a try block][requires: import java.lang.reflect.Field] JavaScript: for (const [vProp, vValue] of Object.entries(oObj)) [also: for (var vProp in oObj)] Kotlin: ___ PHP: foreach ($oObj as $vProp=>$vValue) Python: for vProp, vValue in oObj.__dict__.items(): Swift: for (vProp, vValue) in Mirror(reflecting:oObj).children UFL: (Range.LoopDemo) [loop through the items of a range, get values one-by-one] AutoHotkey: ___ C++: for (const auto& vValue : oRange) C#: foreach (var vValue in oRange) Excel: ___ Excel VBA: ___ Java: for (var vValue : (Iterable<Integer>)oRange::iterator) [also: oRange.forEach(v->System.out.println(v))][WARNING (both): the iterations are terminal operations, that make oRange unusable] JavaScript: ___ Kotlin: for (vValue in oRange) PHP: ___ Python: for vValue in oRange: Swift: for vValue in oRange Section: Array Methods UFL: Array.Rept [or Array.Repeat][create an array of the same value repeated n times] AutoHotkey: ___ C++: std::fill(oArray, oArray+vCount, vValue) [beforehand: int* oArray = new int[vCount]][also (array): std::fill(std::begin(oArray), std::end(oArray), vValue)][also (vector): std::fill(oVec.begin(), oVec.end(), vValue)][beforehand (vector): std::vector<int> oVec(vCount)] C#: Array.Fill(oArray, vValue) [beforehand: int[] oArray = new int[vCount]][also (requires: using System.Linq): int[] oArray = Enumerable.Repeat(vValue, vCount).ToArray()] Excel: ___ Excel VBA: ___ Java: java.util.Arrays.fill(oArray, vValue) [beforehand: int[] oArray = new int[vCount]] JavaScript: oArray = Array(vCount).fill(vValue) [also (ES5): Array.apply(null, Array(vCount)).map(function(){return vValue})] Kotlin: oArray = IntArray(vCount){vValue} PHP: $oArray = array_fill($vIndex, $vCount, $vValue) [e.g. $vIndex = 0 for a 0-based array][also: $oArray = array_pad([], $vCount, $vValue)] Python: oList = [vValue] * vCount Swift: oArray = Array(repeating:vValue, count:vCount) UFL: (Array.Keys) [often equivalent to range to array] AutoHotkey: oKeys := [oArray.__Enum(2).Bind(,&_)*] C++: for (int i=0; i<sizeof(oArray)/sizeof(oArray[0]); i++) oKeys.push_back(i) [beforehand: std::vector<int> oKeys] C#: ___ [can use: var oKeys = Enumerable.Range(0, oArray.Length).ToArray()] Excel: ___ Excel VBA: ___ Java: ___ [can use: var oKeys = IntStream.range(0, oArray.length).toArray()] JavaScript: oKeys = oArray.keys() Kotlin: oKeys = oArray.mapIndexed{k,_->k}.toTypedArray() [also: oKeys = (0..<oArray.count()).toList().toTypedArray()] PHP: $oKeys = array_keys($oArray) Python: ___ [can use: oKeys = list(range(len(oList)))] Swift: oKeys = oArray.enumerated().map{$0.0} [note: failed with $0] UFL: (Array.Values) [often equivalent to copying an array] AutoHotkey: oValues := [oArray*] [also: oValues := oArray.Clone()] C++: for (int i=0; i<sizeof(oArray)/sizeof(oArray[0]); i++) oValues.push_back(oArray[i]) [beforehand: std::vector<std::string> oValues] C#: ___ [can use: var oValues = oArray.Clone() as string[]][note: replace 'string[]' with the appropriate type] Excel: ___ Excel VBA: ___ [can use (clone array): oValues = oArray] Java: ___ [can use: var oValues = oArray.clone()] JavaScript: oValues = oArray.values() [also: oValues = oArray.slice()] Kotlin: ___ [can use: oValues = oArray.copyOf()] PHP: $oValues = array_values($oArray) [also (clone array): $oValues = $oArray] Python: ___ [can use: oValues = oList.copy()] Swift: oValues = oArray.map{$0} [also (clone array): oValues = oArray] UFL: (Array.Entries) [or Array.ToEntries][array to entries (key-value pairs)] AutoHotkey: ___ C++: for (int i=0; i<sizeof(oArray)/sizeof(oArray[0]); i++) oEntries.push_back(std::make_pair(i, oArray[i])) [beforehand: std::vector<std::pair<int,std::string>> oEntries] C#: Tuple<int,string>[] oEntries = oArray.Select((v,k)=>new Tuple<int,string>(k,v)).ToArray() [also: KeyValuePair<int,string>[] oEntries = oArray.Select((v,k)=>new KeyValuePair<int,string>(k,v)).ToArray()][also: string[][] oEntries = oArray.Select((v,k)=>new[]{k.ToString(),v}).ToArray()] Excel: ___ Excel VBA: ___ Java: for (int i=0; i<oArray.length; i++) oEntries[i] = Map.entry(i, oArray[i]) [beforehand: Map.Entry<Integer,String>[] oEntries = new Map.Entry[oArray.length]][also (indexes as strings): for (int i=0; i<oArray.length; i++) oEntries[i] = new String[]{"" + i, oArray[i]}][beforehand (indexes as strings): String[][] oEntries = new String[oArray.length][2]] JavaScript: oEntries = oArray.entries() Kotlin: oEntries = oArray.mapIndexed{k,v->k to v!!}.toMap().entries PHP: foreach ($oArray as $vKey=>$vValue) array_push($oEntries, [$vKey, $vValue]) [beforehand: $oEntries = []][also: $oEntries = array_map(function($oKey) use ($oArray) {return [$oKey, $oArray[$oKey]];}, array_keys($oArray))] Python: oEntries = {k:v for k,v in enumerate(oList)}.items() Swift: oEntries = oArray.enumerated().map{[$0,$1]} UFL: Array.Flat [or Array.Flatten][note: modifies the array] AutoHotkey: ___ C++: ___ C#: ___ Excel: ___ Excel VBA: ___ Java: ___ JavaScript: oArray.flat(vDepth) [note: default depth: 1] Kotlin: oArray.flatten() PHP: ___ Python: ___ Swift: ___ UFL: (Array.Flattened) [note: doesn't modify the array] AutoHotkey: ___ C++: ___ [e.g. 2D array: for (const auto& oEntry : oEntries) oVec.insert(oVec.end(), oEntry, oEntry+2)][beforehand (e.g.): std::vector<std::string> oVec][beforehand (e.g.) std::vector<int> oVec] C#: oArrayNew = oArray.SelectMany(v=>v) Excel: ___ Excel VBA: ___ Java: ___ [e.g. flatten String[][]: String[] oArray = Arrays.stream(oEntries).flatMap(Arrays::stream).toArray(String[]::new)][e.g. flatten int[][]: int[] oArray = Arrays.stream(oEntries).flatMapToInt(Arrays::stream).toArray()] JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ Swift: oArrayNew = oArray.flatMap{$0} [WARNING: only flattens by 1 level] UFL: Array.Length AutoHotkey: oArray.Length [note: AHK v1: oArray.Length()] C++: sizeof(oArray)/sizeof(oArray[0]) [also: vLen = *(&oArray+1) - oArray][note (std::vector): oVec.size()][also: vLen = std::end(oArray) - std::begin(oArray)] C#: oArray.Length Excel: ___ Excel VBA: vLen = UBound(oArray) - LBound(oArray) + 1 [note: this works for empty arrays too, e.g. Array() has UBound -1 and LBound 0] Java: oArray.length JavaScript: oArray.length Kotlin: oArray.size [also: oArray.count()] PHP: count($oArray) [also: sizeof($oArray)] Python: len(oList) Swift: oArray.count UFL: Array.CountNonNull [no params: count items with a value][e.g. check if array is dense] AutoHotkey: ___ C++: for (const auto& vValue : oArray) if (vValue != (std::string)NULL) vCount++ [beforehand: int vCount = 0] C#: vCount = oArray.Count(v=>v!=null) Excel: ___ Excel VBA: ___ [note: can use Filter() to list matches(/non-matches) that are a *substring* of a needle, case-sensitive/case-insensitive (integer values are treated as strings)] Java: ___ [e.g. Integer[]: int vCount = Arrays.stream(oArray).reduce(0,(a,v)->a+(v!=null?1:0))] JavaScript: ___ Kotlin: ___ PHP: $vCount = count(array_filter($oArray, function($oValue) {return ($oValue != null);})) Python: ___ Swift: vCount = oArray.reduce(0){$0+($1==nil ?1:0)} [note: if '?' 'has no whitespace on the left, it's treated as a postfix operator'] UFL: Array.Count [or Array.CountMatch][1 param: count items that match predicate (i.e. like Array.Filter but the count only, not the matches)][see also: Array.Filter] AutoHotkey: ___ C++: for (const auto& vValue : oArray) if (vValue == vNeedle) vCount++ [beforehand: int vCount = 0] C#: vCount = oArray.Count(oFunc) [also: oArray.TrueForAll(oFunc) checks whether all elements match] Excel: ___ Excel VBA: ___ [note: can use Filter() to list matches(/non-matches) that are a *substring* of a needle, case-sensitive/case-insensitive (integer values are treated as strings)] Java: ___ [e.g. int[]: int vCount = Arrays.stream(oArray).boxed().reduce(0,(a,v)->a+(v==vNeedle?1:0))][e.g. int[] also: long vCount = Arrays.stream(oArray).boxed().filter(v->v==vNeedle).count()][e.g. String[]: int vCount = Arrays.stream(oArray).reduce(0,(a,v)->a+(v==vNeedle?1:0),Integer::sum)][e.g. String[] also: long vCount = Arrays.stream(oArray).filter(v->v==vNeedle).count()] JavaScript: ___ Kotlin: vCount = oArray.count(oFunc) PHP: $vCount = count(array_filter($oArray, function($oValue) use ($vNeedle) {return ($oValue == $vNeedle);})) Python: ___ Swift: vCount = oArray.reduce(0){$0+($1==vNeedle ?1:0)} UFL: Array.GetCapacity [get array capacity] AutoHotkey: vCapacity := oArray.Capacity C++: vCapacity = oVec.capacity() C#: vCapacity = oList.Capacity Excel: ___ Excel VBA: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ Swift: vCapacity = oArray.capacity UFL: Array.SetCapacity [set array capacity (or request a minimum capacity)] AutoHotkey: oArray.Capacity := vCapacity C++: oVec.reserve(vCapacity) [also: oVec.shrink_to_fit()] C#: oList.Capacity = vCapacity Excel: ___ Excel VBA: ___ Java: oList.ensureCapacity(vCapacity) [also: oList.trimToSize()] JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ Swift: oArray.reserveCapacity(vCapacity) UFL: Array.Has [or Array.HasKey] AutoHotkey: vHasKey = oArray.Has(vKey) C++: vHasKey = (vKey < sizeof(oArray)/sizeof(oArray[0])) [also: (oArray[vKey] != (std::string)NULL)] C#: vHasKey = (vKey < oArray.Length) [also: (oArray[vKey] != null)] Excel: ___ Excel VBA: vHasKey = (TypeName(oArray(vKey)) != "Empty") [also: vHasKey = (LBound(oArray) <= vKey) And (vKey <= UBound(oArray))] Java: var vHasKey = (vKey < oArray.length) [also: (oArray[vKey] != null)] JavaScript: vHasKey = (vKey in oArray) [note: empty (elided) items return false, undefined/null items return true] Kotlin: vHasKey = (vKey < oArray.size) [also: (oArray[vKey] != null)] PHP: $vHasKey = array_key_exists($vKey, $oArray) Python: vHasKey = (vKey < len(oList)) [also: (oList[vKey] is not None)] Swift: vHasKey = (vKey < oArray.count) [also: oArray[vKey] != nil] UFL: (Array.KeyIsEmpty) AutoHotkey: ___ [can use: IsSet(vValue)][note: cannot use IsSet(oArray[vKey]), must do vValue := oArray[vKey] first, IsSet is not a standard function] C++: vKeyIsEmpty = (oArray[vKey] == (std::string)NULL) C#: vKeyIsEmpty = (oArray[vKey] == null) Excel: ___ Excel VBA: vKeyIsEmpty = (TypeName(oArray(vKey)) = "Empty") Java: var vKeyIsEmpty = (oArray[vKey] == null) JavaScript: vKeyIsEmpty = !(vKey in oArray) Kotlin: vKeyIsEmpty = (oArray[vKey] == null) PHP: $vKeyIsEmpty = ($oArray[$vKey] == null) Python: vKeyIsEmpty = (oList[vKey] is None) [inverse: (oList[vKey] is not None)] Swift: vKeyIsEmpty = (oArray[vKey] == nil) UFL: Array.HasVal [or Array.HasValue (contains/includes value)] AutoHotkey: ___ C++: auto vHasVal = (std::find(std::begin(oArray), std::end(oArray), vNeedle) == std::end(oArray)) [also: auto vHasVal = (std::find(oVec.begin(), oVec.end(), vNeedle) == oVec.end())] C#: vHasVal = oArray.Contains(vValue) [also: Array.Exists(oArray, v=>v==vValue)] Excel: ___ Excel VBA: ___ [note: can use Filter() to list matches(/non-matches) that are a *substring* of a needle, case-sensitive/case-insensitive (integer values are treated as strings)] Java: ___ [can use: var vHasVal = (oList.indexOf(vValue) != -1)][also (String[]): var vHasVal = Arrays.asList(oArray).contains(vNeedle)][also (String[]): var vHasVal = Arrays.stream(oArray).anyMatch(vNeedle::equals)][also (int[]): var vHasVal = IntStream.of(oArray).anyMatch(v->v==vNeedle)] JavaScript: vHasVal = oArray.includes(vValue) Kotlin: vHasVal = oArray.contains(vValue) PHP: $vHasVal = in_array($vValue, $oArray) Python: ___ [can use (throws if not found): oList.index(vValue)] Swift: vHasVal = oArray.contains(vValue) UFL: Array.IndexOf [potentially also: (Array.IndexOf0B)/(Array.IndexOf1B) (note: typically return -1 or 0 on failure)] AutoHotkey: ___ C++: auto vIndex = std::find(std::begin(oArray), std::end(oArray), vNeedle) - oArray [also: auto vIndex = std::find(oVec.begin(), oVec.end(), vNeedle) - oVec.begin()][note (both): returns array length (or vector size) if value not found] C#: vKey = Array.IndexOf(oArray, vValue) Excel: ___ Excel VBA: ___ Java: vKey = oList.indexOf(vValue) JavaScript: vKey = oArray.indexOf(vValue) Kotlin: vKey = oArray.indexOf(vValue) PHP: $vKey = array_search($vValue, $oArray) [WARNING: since PHP arrays are associative arrays, -1 is a valid key name, hence boolean false is returned on failure] Python: vKey = oList.index(vValue) [WARNING: throws if not found] Swift: ___ [can use: vKey = oArray.firstIndex(of:vValue) ?? -1] UFL: Array.LastIndexOf [(note: typically return -1 or 0 on failure)] AutoHotkey: ___ C++: auto vIndex = oVec.rend() - std::find(oVec.rbegin(), oVec.rend(), vNeedle) - 1 [note: returns -1 if value not found] C#: vKey = Array.LastIndexOf(oArray, vValue) Excel: ___ Excel VBA: ___ Java: vKey = oList.lastIndexOf(vValue) JavaScript: vKey = oArray.lastIndexOf(vValue) Kotlin: vKey = oArray.lastIndexOf(vValue) [note: don't confuse with indexOfLast] PHP: $vKey = array_search($vValue, array_reverse($oArray, true)) [note: array_reverse() doesn't modify the array][note: array_reverse(): preserve_keys set to true][WARNING: since PHP arrays are associative arrays, -1 is a valid key name, hence boolean false is returned on failure] Python: vKey = max(k for k,v in enumerate(oList) if v==vValue) [WARNING: throws if not found, consistent with oList.index()] Swift: ___ [can use: vKey = oArray.lastIndex(of:vValue) ?? -1] UFL: Array.Get AutoHotkey: vValue := oArray[vKey] C++: vValue = oArray[vKey] [also: vValue = oVec[vKey]] C#: vValue = oArray[vKey] [also: oArray.GetValue()] Excel: ___ Excel VBA: vValue = oArray(vKey) Java: vValue = oArray[vKey] [also: vValue = oList.get(vKey)] JavaScript: vValue = oArray[vKey] Kotlin: vValue = oArray[vKey] [also: vValue = oArray.get(vKey)] PHP: $vValue = $oArray[$vKey] Python: vValue = oList[vKey] Swift: vValue = oArray[vKey] UFL: Array.GetOrDefault [if key non-existent/null/beyond length, provide default (deviations from this are noted)] AutoHotkey: vValue := oArray.Get(vKey, vDefault) [WARNING: throws if key beyond length] C++: ___ C#: ___ [can use: oArray.ElementAtOrDefault(vKey)][WARNING (ElementAtOrDefault): returns null if value is null][note (ElementAtOrDefault): returns default if key beyond length][note (ElementAtOrDefault): can't specify a default, the defaults for int/double/string are 0/0/"" respectively][also: oArray[vKey] ?? vDefault][WARNING: oArray[vKey] throws if key beyond length] Excel: ___ Excel VBA: ___ Java: vValue = Optional.ofNullable(oArray[vKey]).orElse(vDefault) [WARNING: throws if key beyond length] JavaScript: vValue = oArray[vKey] ?? vDefault [note: returns default if value is null/undefined][note: returns default if key beyond length] Kotlin: vValue = oArray.getOrElse(vKey, oFunc) [e.g. oArray.getOrElse(vKey, {vDefault})][e.g. oArray.getOrElse(vKey){vDefault}][WARNING (unlike maps): returns null if value is null][note: returns default if key beyond length][also: oArray[vKey] ?: vDefault][WARNING: oArray[vKey] throws if key beyond length] PHP: $vValue = $oArray[$vKey] ?? $vDefault Python: ___ [can use: vValue = (oList[vKey:vKey+1]or[vDefault])[0]][also: (oList[vKey:vKey+1]+[vDefault])[0]][WARNING (both): returns None if value is None] Swift: vValue = oArray[vKey] ?? vDefault [WARNING: throws if key beyond length] UFL: Array.Set AutoHotkey: oArray[vKey] := vValue C++: oArray[vKey] = vValue [also: oVec[vKey] = vValue] C#: oArray[vKey] = vValue [also: oArray.SetValue()] Excel: ___ Excel VBA: oArray(vKey) = vValue Java: oArray[vKey] = vValue [also: oList.set(vKey, vValue)] JavaScript: oArray[vKey] = vValue Kotlin: oArray[vKey] = vValue [also: oArray.set(vKey, vValue)] PHP: $oArray[$vKey] = $vValue Python: oList[vKey] = vValue Swift: oArray[vKey] = vValue UFL: Array.Swap AutoHotkey: ___ C++: std::swap(oArray[vKey1], oArray[vKey2]) [also: std::iter_swap(oVec.begin()+vKey1, oVec.begin()+vKey2)][requires (std::iter_swap): #include <algorithm>] C#: (oArray[vKey1], oArray[vKey2]) = (oArray[vKey2], oArray[vKey1]) [note: destructuring assignment] Excel: ___ Excel VBA: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: [$oArray[$vKey1], $oArray[$vKey2]] = [$oArray[$vKey2], $oArray[$vKey1]] [note: destructuring assignment] Python: oList[vKey1], oList[vKey2] = oList[vKey2], oList[vKey1] [note: destructuring assignment] Swift: oArray.swapAt(vKey1, vKey2) [also (destructuring assignment): (oArray[vKey1], oArray[vKey2]) = (oArray[vKey2], oArray[vKey1])][note: swap() fails with 'overlapping accesses' error: swap(&oArray[vKey1], &oArray[vKey2])] UFL: (Array.Swapped) AutoHotkey: ___ C++: ___ C#: ___ Excel: ___ Excel VBA: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ Swift: ___ UFL: Array.Push [append one value] AutoHotkey: oArray.Push(vValue) C++: oVec.push_back(vValue) C#: var oArrayNew = oArray.Append(vValue).ToArray() [requires (Append/Concat): using System.Linq][also: var oArray = oArray.Concat(new[]{vValue}).ToArray()][also: Array.Resize(ref oArray, oArray.Length+1); oArray[oArray.GetUpperBound(0)] = vValue;][also: var oList = oArray.ToList(); oList.Add(vValue); var oArrayNew = oList.ToArray();] Excel: ___ Excel VBA: ReDim Preserve oArray(UBound(oArray) + 1) [afterwards: oArray(UBound(oArray)) = vValue] Java: oList.add(vValue) JavaScript: oArray.push(vValue) Kotlin: oArray.add(vValue) PHP: array_push($oArray, $vValue) [note: it finds the maximum (non-negative) integer key n, and creates key n+1, else creates key 0] Python: oList.append(vValue) Swift: oArray.append(vValue) UFL: Array.PushMult [or Array.PushArray][append multiple values][modify an array by appending (the values of) another array to it (concatenate arrays)] AutoHotkey: oArray1.Push(oArray2*) C++: oVec1.insert(oVec1.end(), oVec2.begin(), oVec2.end()) [can use (to create a new array): auto* oArrayNew = new std::string[vSize1+vSize2]][can use (to copy elements): std::copy()] C#: var oArrayNew = oArray1.Concat(oArray2).ToArray() [requires (Concat): using System.Linq][also: var oList = oArray1.ToList(); oList.AddRange(oArray2); var oArrayNew = oList.ToArray();][also: CopyTo()][also: Resize() and Copy()] Excel: ___ Excel VBA: ___ Java: oList1.addAll(oList2) [also (concatenate via arraycopy): System.arraycopy(oArray2, 0, oArrayNew, oArray1.length, oArray2.length)][beforehand (concatenate via arraycopy): var oArrayNew = Arrays.copyOf(oArray1, oArray1.length+oArray2.length)][also (concatenate via streams): String[] oArrayNew = Stream.concat(Arrays.stream(oArray1), Arrays.stream(oArray2)).toArray(String[]::new)][requires (concatenate via streams): import java.util.stream.*] JavaScript: oArray1.push(...oArray2) Kotlin: oArray1 += oArray2 PHP: array_push($oArray1, ...$oArray2) [also: $oArrayNew = array_merge($oArray1, $oArray2)] Python: oList1.extend(oList2) Swift: oArray1.append(contentsOf: oArray2) [also: oArray1 += oArray2] UFL: Array.InsertAt [insert one item (and shift item(s) right)] AutoHotkey: oArray.InsertAt(vKey, vValue) C++: oVec.insert(oVec.begin()+vKey, vValue) C#: oList.Insert(vKey, vValue) [e.g. var oList = oArray.ToList(); oList.Insert(vKey, vValue); var oArrayNew = oList.ToArray();] Excel: ___ Excel VBA: ___ Java: oList.add(vKey, vValue) JavaScript: oArray.splice(vKey, 0, vValue) Kotlin: ___ [can use: copyOfRange and +, sliceArray and +, toMutableList and add] PHP: array_splice($oArray, $vKey, 0, [$vValue]) Python: oList.insert(vKey, vValue) Swift: oArray.insert(vValue, at:vKey) UFL: Array.InsertAtMult [insert item(s) (and shift item(s) right)] AutoHotkey: oArray1.InsertAt(vKey, oArray2*) C++: oVec1.insert(oVec1.begin()+vKey, oVec2.begin(), oVec2.end()) C#: oList.InsertRange(vKey, oArray2) [e.g. var oList = oArray.ToList(); oList.InsertRange(vKey, oArray2); var oArrayNew = oList.ToArray();] Excel: ___ Excel VBA: ___ Java: oList1.addAll(vKey, oList2) JavaScript: oArray1.splice(vKey, 0, ...oArray2) Kotlin: ___ [can use: copyOfRange and +, sliceArray and +, toMutableList and add] PHP: array_splice($oArray1, $vKey, 0, $oArray2) Python: oList1[vKey:vKey] = oList2 [note: slice assignment] Swift: oArray1.insert(contentsOf:oArray2, at:vKey) UFL: (Array.Prepend) [or Array.InsertAtStart][insert one item at start (and shift item(s) right)] AutoHotkey: oArray.InsertAt(1, vValue) C++: oVec.insert(oVec.begin(), vValue) C#: var oArrayNew = oArray.Prepend(vValue).ToArray() [requires (Prepend/Concat): using System.Linq][also: var oArrayNew = new[]{vValue}.Concat(oArray).ToArray()][also: var oList = oArray.ToList(); oList.Insert(0, vValue); var oArrayNew = oList.ToArray();] Excel: ___ Excel VBA: ___ Java: oList.add(0, vValue) JavaScript: oArray.unshift(vValue) Kotlin: ___ [can use: copyOfRange and +, sliceArray and +, toMutableList and add] PHP: array_unshift($oArray, $vValue) Python: oList.insert(0, vValue) Swift: oArray.insert(vValue, at:0) UFL: (Array.PrependMult) [or Array.InsertAtStartMult][insert item(s) at start (and shift item(s) right)] AutoHotkey: oArray1.InsertAt(1, oArray2*) C++: oVec1.insert(oVec1.begin(), oVec2.begin(), oVec2.end()) C#: var oArrayNew = oArray2.Concat(oArray1).ToArray() [requires (Concat): using System.Linq][also: var oList = oArray1.ToList(); oList.InsertRange(0, oArray2); var oArrayNew = oList.ToArray();] Excel: ___ Excel VBA: ___ Java: oList1.addAll(0, oList2) JavaScript: oArray1.unshift(...oArray2) Kotlin: ___ [can use: copyOfRange and +, sliceArray and +, toMutableList and add] PHP: array_unshift($oArray1, ...$oArray2) Python: oList1[:0] = oList2 [note: slice assignment] Swift: oArray1.insert(contentsOf:oArray2, at:0) UFL: Array.Pop [or Array.RemoveLast][remove last value] AutoHotkey: oArray.Pop() C++: oVec.pop_back() C#: var oArrayNew = oArray.SkipLast(1).ToArray() [requires (SkipLast): using System.Linq] Excel: ___ Excel VBA: ReDim Preserve oArray(UBound(oArray) - 1) [beforehand: vValue = oArray(UBound(oArray))] Java: oList.remove(oList.size()-1) [also: var oArrayNew = Arrays.copyOfRange(oArray, 0, oArray.length-1)] JavaScript: oArray.pop() Kotlin: oArrayNew = oArray.dropLast(1).toTypedArray() PHP: array_pop($oArray) [WARNING: removes the last key to be added (not necessarily an integer key, not necessarily the largest integer key)][can use (to get the key name): array_key_last($oArray)] Python: oList.pop() Swift: oArray.removeLast() [also: oArray.popLast()][also: oArrayNew = Array(oArray.dropLast())] UFL: Array.PopMult [or Array.RemoveLastMult][remove multiple values] AutoHotkey: oArray.RemoveAt(-vCount, vCount) C++: oVec.resize(oVec.size()-vCount > 0 ? oVec.size()-vCount : 0) C#: oArrayNew = oArray.SkipLast(vCount).ToArray() [requires (SkipLast): using System.Linq] Excel: ___ Excel VBA: ReDim Preserve oArray(UBound(oArray) - vCount) Java: var oArrayNew = Arrays.copyOfRange(oArray, 0, oArray.length-vCount) [WARNING: ArrayList.removeRange() has protected access] JavaScript: oArray.splice(-vCount) Kotlin: oArrayNew = oArray.dropLast(vCount).toTypedArray() PHP: array_splice($oArray, -$vCount) Python: oListNew = oList[:-3] Swift: oArray.removeLast(vCount) [also: oArrayNew = Array(oArray.dropLast(vCount))] UFL: Array.RemoveAt [remove one item (and shift item(s) left)] AutoHotkey: oArray.RemoveAt(vKey) C++: oVec.erase(oVec.begin()+vKey) C#: oList.RemoveAt(vKey) [e.g. var oList = oArray.ToList(); oList.RemoveAt(vKey); var oArrayNew = oList.ToArray();] Excel: ___ Excel VBA: ___ Java: oList.remove(vKey) JavaScript: oArray.splice(vKey, 1) Kotlin: ___ [can use: copyOfRange and +, sliceArray and +, toMutableList and removeAt/subList] PHP: array_splice($oArray, $vKey, 1) Python: oList.pop(vKey) [WARNING: called 'pop' but can remove from any location] Swift: oArray.remove(at:vKey) UFL: Array.RemoveAtMult [remove item(s) (and shift item(s) left)] AutoHotkey: oArray.RemoveAt(vKey, vCount) C++: oVec.erase(oVec.begin()+vKey, oVec.begin()+vKey+vCount) C#: oList.RemoveRange(vKey, vCount) [e.g. var oList = oArray.ToList(); oList.RemoveRange(vKey, vCount); var oArrayNew = oList.ToArray();] Excel: ___ Excel VBA: ___ Java: ___ [WARNING: ArrayList.removeRange() has protected access] JavaScript: oArray.splice(vKey, vCount) Kotlin: ___ [can use: copyOfRange and +, sliceArray and +, toMutableList and removeAt/subList] PHP: array_splice($oArray, $vKey, $vCount) Python: del oList[vKey:vKey+vCount] Swift: oArray.removeSubrange(vKey..<vKey+vCount) UFL: (Array.RemoveFirst) [remove first item/element] AutoHotkey: oArray.RemoveAt(1) C++: oVec.erase(oVec.begin()) C#: var oArrayNew = oArray.Skip(1).ToArray() [requires (Skip): using System.Linq] Excel: ___ Excel VBA: ___ Java: oList.remove(0) [also: var oArrayNew = Arrays.copyOfRange(oArray, 1, oArray.length)] JavaScript: oArray.shift() Kotlin: oArrayNew = oArray.drop(1).toTypedArray() [can use: oList = oArray.toMutableList(), oList.removeFirst(), oArrayNew = oList.toTypedArray()][can use (instead of removeFirst()): oList.removeAt(0)] PHP: array_shift($oArray) [note: get name of first key: array_key_first($oArray)] Python: oList.pop(0) [WARNING: called 'pop' but can remove from any location][also: del oList[:1]] Swift: oArray.removeFirst() [also: oArrayNew = Array(oArray.dropFirst())] UFL: (Array.RemoveFirstMult) AutoHotkey: oArray.RemoveAt(1, vCount) C++: oVec.erase(oVec.begin(), oVec.begin()+vCount) C#: var oArrayNew = oArray.Skip(vCount).ToArray() [requires (Skip): using System.Linq] Excel: ___ Excel VBA: ___ Java: var oArrayNew = Arrays.copyOfRange(oArray, vCount, oArray.length) [WARNING: ArrayList.removeRange() has protected access] JavaScript: oArray.splice(0, vCount) Kotlin: oArrayNew = oArray.drop(vCount).toTypedArray() PHP: array_splice($oArray, 0, $vCount) Python: del oList[:vCount] Swift: oArray.removeFirst(vCount) [also: oArrayNew = Array(oArray.dropFirst(vCount))] UFL: Array.Splice [or Array.RemoveAndInsert][remove n elements (and shift elements left), and insert 0 or more elements] AutoHotkey: ___ C++: ___ C#: ___ Excel: ___ Excel VBA: ___ Java: ___ JavaScript: oArray1.splice(vKey, vCount, ...oArray2) Kotlin: ___ PHP: array_splice($oArray1, $vKey, $vCount, $oArray2) Python: oList1[vKey:vKey+vCount] = oList2 [note: slice assignment] Swift: oArray1.replaceSubrange(vKey..<vKey+vCount, with:oArray2) UFL: Array.Delete [delete a key, but maintain the positions of other keys] AutoHotkey: oArray.Delete(vKey) C++: ___ C#: oArray[vKey] = null Excel: ___ Excel VBA: oArray(vKey) = Empty Java: oArray[vKey] = null JavaScript: delete oArray[vKey] [note: sets the key to empty (elided)][also: oArray[vKey] = undefined] Kotlin: oArray[vKey] = null PHP: $oArray[$vKey] = null [also: unset($oArray[$vKey])] Python: oList[vKey] = None Swift: oArray[vKey] = nil UFL: Array.Clear [or Array.DeleteAll or Array.Empty] AutoHotkey: oArray.Length := 0 C++: ___ [can use (for array on the heap): oArray = new int[0]][also: oVec.clear()][also: oVec = {}][WARNING: oVec.empty() returns whether the vector is empty or not] C#: Array.Resize(ref oArray, 0) Excel: ___ Excel VBA: ReDim oArray(0) Java: oArray = new int[]{} JavaScript: oArray.length = 0 Kotlin: oArray.clear() PHP: $oArray = [] [also: array_splice($oArray, 0, count($oArray))][note: appears to work even if the array has no '0' key] Python: oList.clear() Swift: oArray.removeAll() UFL: Array.Clone [or Array.Copy][copy the entire array] AutoHotkey: oArrayNew := oArray.Clone() C++: std::copy(std::begin(oArray), std::end(oArray), std::begin(oArrayNew)) [also: std::copy(std::begin(oArray), std::end(oArray), oArrayNew)][also: auto oVecNew = oVec][also: std::vector<int> oVecNew(oVec)][also: std::copy(oVec.begin(), oVec.end(), std::back_inserter(oVecNew))][note: 'oArrayNew = oArray' causes an error] C#: oArrayNew = oArray.Clone() as string[] [also: oArrayNew = (string[])oArray.Clone()][note: replace 'string[]' with the appropriate type] Excel: ___ Excel VBA: oArrayNew = oArray [WARNING: this copies the object, not a reference][i.e. in many languages, this syntax would result in 2 variables pointing to the same object] Java: oArrayNew = oArray.clone() JavaScript: oArrayNew = oArray.slice() Kotlin: oArrayNew = oArray.copyOf() PHP: $oArrayNew = $oArray [WARNING: this copies the object, not a reference] Python: oListNew = oList.copy() Swift: oArrayNew = oArray [WARNING: this copies the object, not a reference][also: oArrayNew = oArray.map{$0}] UFL: Array.SliceTo [create a copy of keys a (inclusive) to b (inclusive)][less common, but more intuitive] AutoHotkey: ___ C++: auto oVecNew = std::vector<std::string>(oVec.begin()+vKey1, oVec.begin()+vKey2+1); C#: var oArrayNew = oArray[vKey1..(vKey2+1)] [also: var oArrayNew = oArray.ToList().Take(vKey1..(vKey2+1)).ToArray()][WARNING: the C# '..' operator is end exclusive] Excel: ___ Excel VBA: ___ Java: var oArrayNew = Arrays.copyOfRange(oArray, vKey1, vKey2+1) [WARNING: appends default values if endpoint goes beyond array] JavaScript: ___ Kotlin: oArrayNew = oArray.slice(vKey1..vKey2).toTypedArray() PHP: $oArrayNew = array_slice($oArray, $vKey1, $vKey2-$vKey1+1) Python: ___ Swift: oArrayNew = Array(oArray[vKey1...vKey2]) UFL: Array.SliceUntil [create a copy of keys a (inclusive) to b (exclusive)] AutoHotkey: ___ C++: auto oVecNew = std::vector<std::string>(oVec.begin()+vKey1, oVec.begin()+vKey2); C#: var oArrayNew = oArray[vKey1..vKey2] [also: var oArrayNew = oArray.ToList().Take(vKey1..vKey2).ToArray()][WARNING: the C# '..' operator is end exclusive] Excel: ___ Excel VBA: ___ Java: var oArrayNew = Arrays.copyOfRange(oArray, vKey1, vKey2) [WARNING: appends default values if endpoint goes beyond array] JavaScript: oArrayNew = oArray.slice(vKey1, vKey2) Kotlin: oArrayNew = oArray.slice(vKey1..<vKey2).toTypedArray() PHP: $oArrayNew = array_slice($oArray, $vKey1, $vKey2-$vKey1) Python: oListNew = oList[vKey1:vKey2] Swift: oArrayNew = Array(oArray[vKey1..<vKey2]) UFL: Array.SliceFirst [create a copy of first n keys] AutoHotkey: ___ C++: auto oVecNew = std::vector<std::string>(oVec.begin(), oVec.begin()+vCount); C#: var oArrayNew = oArray[..vCount] [also: var oArrayNew = oArray.Take(vCount).ToArray()][WARNING: the C# '..' operator is end exclusive] Excel: ___ Excel VBA: ___ Java: var oArrayNew = Arrays.copyOfRange(oArray, 0, Math.min(vCount, oArray.length)) JavaScript: oArrayNew = oArray.slice(0, vCount) Kotlin: oArrayNew = oArray.take(vCount).toTypedArray() [also: oArrayNew = oArray.slice(0..<vCount).toTypedArray()] PHP: $oArrayNew = array_slice($oArray, 0, $vCount) Python: oListNew = oList[:vCount] Swift: oArrayNew = Array(oArray.prefix(vCount)) UFL: Array.SliceLast [create a copy of last n keys] AutoHotkey: ___ C++: auto oVecNew = std::vector<std::string>(oVec.end()-vCount, oVec.end()); C#: var oArrayNew = oArray[Math.Max(oArray.Length-vCount, 0)..] [also: var oArrayNew = oArray.TakeLast(vCount).ToArray()][WARNING: the C# '..' operator is end exclusive] Excel: ___ Excel VBA: ___ Java: var oArrayNew = Arrays.copyOfRange(oArray, Math.max(oArray.length-vCount, 0), oArray.length) JavaScript: oArrayNew = oArray.slice(-vCount) Kotlin: oArrayNew = oArray.takeLast(vCount).toTypedArray() PHP: $oArrayNew = array_slice($oArray, -$vCount) Python: oListNew = oList[-vCount:] Swift: oArrayNew = Array(oArray.suffix(vCount)) UFL: Array.ToString [see also: Array.Join] AutoHotkey: ___ C++: ___ C#: ___ [can use: String.Join(vSep, oArray)] Excel: ___ [can use: TEXTJOIN()] Excel VBA: ___ [can use: Join(oArray, vSep)] Java: java.util.Arrays.toString(oArray) [also (for string arrays): String.join(vSep, oArray)] JavaScript: oArray.toString() Kotlin: oArray.toList().toString() PHP: ___ [can use: implode($vSep, $oArray)][also (alias): join($vSep, $oArray)] Python: str(oList) Swift: oArray.description [also (for string arrays): oArray.joined(separator:vSep)] UFL: Array.Join [see also: Array.ToString] AutoHotkey: ___ C++: ___ [can use (string array): std::string vText = std::accumulate(std::begin(oArray), std::end(oArray), std::string(""), [&vSep](std::string a,std::string v){return a+v+vSep;})][also (string vector): std::string vText = std::accumulate(oVec.begin(), oVec.end(), std::string(""), [&vSep](std::string a,std::string v){return a+v+vSep;})][WARNING (both): adds a trailing separator][requires (std::accumulate): #include <numeric>][e.g. join no separator: std::string vText = std::accumulate(std::begin(oArray), std::end(oArray), std::string(""))][note: can replace '[&vSep]' with '[vSep]'] C#: String.Join(vSep, oArray) Excel: ___ [can use: TEXTJOIN(vSep,, vText1, vText2, vText3)][note: TEXTJOIN (Excel 2016)] Excel VBA: Join(oArray, vSep) Java: String.join(vSep, oArray) [note: for string arrays only][also (for any array): java.util.Arrays.toString(oArray)] JavaScript: oArray.join(vSep) Kotlin: oArray.joinToString(vSep) PHP: implode($vSep, $oArray) [also (alias): join($vSep, $oArray)] Python: vSep.join(oList) [WARNING: can't do: oList.join(vSep)][note: for string lists only][also (for any list): vSep.join(map(str, oList))] Swift: oArray.joined(separator:vSep) [note: for string arrays only][also (for any array): oArray.description] UFL: Array.Sort [note: modifies the array] AutoHotkey: ___ [note: Sort can sort a string by a delimiter char][WARNING (Sort): default sort is alphabetical, to sort numerically: use 'N' mode e.g. vText := Sort(vText, "D" vSep " N")] C++: std::sort(std::begin(oArray), std::end(oArray)) [also: std::sort(oVec.begin(), oVec.end())] C#: Array.Sort(oArray) Excel: ___ Excel VBA: ___ Java: Arrays.sort(oArray) [note: e.g. works on int[] and String[]][requires: import java.util.*] JavaScript: oArray.sort() [WARNING: default sort is alphabetical, to sort numerically: e.g. oArray.sort((v1,v2)=>v1-v2)] Kotlin: oArray.sort() [also: oArray.sortWith(oFunc)] PHP: sort($oArray) [also: usort($oArray, $oFunc)][WARNING: default sort (SORT_REGULAR): sorts strings alphabetically (compares 2 strings numerically if at least 1 is numeric-looking, a 'numeric string'), sorts ints numerically][note: to sort alphabetically: e.g. sort($oArray, SORT_STRING)][note: to sort numerically: e.g. sort($oArray, SORT_NUMERIC)] Python: oList.sort() [WARNING: default sort: sorts strings alphabetically, sorts ints numerically (no special handling for numeric-looking strings), throws if try to compare int with str][note: to sort strings numerically: e.g. oList.sort(key=int)] Swift: oArray.sort() UFL: Array.Sorted [note: doesn't modify the array] AutoHotkey: ___ C++: ___ C#: ___ Excel: ___ Excel VBA: ___ Java: ___ [can use: String[] oArrayNew = Arrays.stream(oArray).sorted().toArray(String[]::new)][requires: import java.util.*] JavaScript: oArrayNew = oArray.toSorted() Kotlin: oArrayNew = oArray.sorted() [also: oArray.sortedWith(oFunc)] PHP: ___ Python: oListNew = sorted(oList) Swift: oArrayNew = oArray.sorted() UFL: Array.Reverse [note: modifies the array] AutoHotkey: ___ C++: std::reverse(std::begin(oArray), std::end(oArray)) [also: std::reverse(oVec.begin(), oVec.end())] C#: Array.Reverse(oArray) Excel: ___ Excel VBA: ___ Java: Collections.reverse(oList) [requires: import java.util.*][WARNING: e.g. for String[]/Integer[] (but not int[]), 'Collections.reverse(Arrays.asList(oArray))' creates a temporary list, and reverses the array] JavaScript: oArray.reverse() Kotlin: oArray.reverse() PHP: ___ Python: oList.reverse() Swift: oArray.reverse() UFL: Array.Reversed [note: doesn't modify the array] AutoHotkey: ___ C++: ___ C#: ___ Excel: ___ Excel VBA: ___ Java: ___ JavaScript: oArrayNew = oArray.toReversed() Kotlin: oArrayNew = oArray.reversed() PHP: $oArrayNew = array_reverse($oArray) [WARNING: array_reverse() creates a new array, it doesn't modify the existing array] Python: oListNew = list(reversed(oList)) Swift: oArrayNew = Array(oArray.reversed()) UFL: (Array.Shuffle) [note: modifies the array] AutoHotkey: ___ C++: std::shuffle(std::begin(oArray), std::end(oArray), oGen) [also: std::shuffle(oVec.begin(), oVec.end(), oGen)][beforehand: std::random_device oRD; std::mt19937 oGen(oRD());][deprecated: std::random_shuffle] C#: ___ Excel: ___ Excel VBA: ___ Java: Collections.shuffle(oList) [requires: import java.util.*][WARNING: e.g. for String[]/Integer[] (but not int[]), 'Collections.shuffle(Arrays.asList(oArray))' creates a temporary list, and shuffles the array] JavaScript: ___ Kotlin: oArray.shuffle() PHP: shuffle($oArray) Python: ___ Swift: oArray.shuffle() UFL: (Array.Shuffled) [note: doesn't modify the array] AutoHotkey: ___ C++: ___ C#: var oArrayNew = oArray.OrderBy(v=>oRand.Next()).ToArray() [beforehand: var oRand = new Random()] Excel: ___ Excel VBA: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ Swift: oArrayNew = oArray.shuffled() UFL: Array.Distinct [or Array.Unique/Array.Dedup/Array.RemoveDups/Array.RemoveDuplicates][remove duplicates, preserve order] AutoHotkey: ___ C++: for (const auto& vValue : oArray) if (!oMap.count(vValue)) oMap[vValue] = 1, oVecNew.push_back(vValue) [beforehand (map): std::map<std::string,int> oMap][beforehand (map/set): std::vector<std::string> oVecNew][WARNING: std::unique only removes adjacent duplicates][also (using set): for (const auto& vValue : oArray) if (!oSet.count(vValue)) oSet.insert(vValue), oVecNew.push_back(vValue)][beforehand (set): std::unordered_set<std::string> oSet][requires (set): #include <unordered_set>] C#: var oArrayNew = oArray.Distinct().ToArray() Excel: ___ Excel VBA: ___ Java: ___ [e.g. String[] oArrayNew = Arrays.stream(oArray).distinct().toArray(String[]::new)][e.g. int[] oArrayNew = Arrays.stream(oArray).distinct().toArray()][e.g. List<Integer>/List<String>: var oListNew = oList.stream().distinct().collect(Collectors.toList())][note (all): preserves order] JavaScript: oArrayNew = [...new Set(oArray)] [note: preserves order] Kotlin: oArrayNew = oArray.distinct() [also: oArray.distinctBy()][note: preserves order] PHP: $oArrayNew = array_values(array_unique($oArray)) [WARNING: array_unique() creates a new array, it doesn't modify the existing array][WARNING: array_unique() maintains indexes, use array_values() to reindex an array][note: preserves order] Python: oListNew = list(dict.fromkeys(oList)) [note: preserves order] Swift: oArrayNew = oArray.reduce(into:[]){$0.contains($1) ?():$0.append($1)} [note: preserves order][also (doesn't preserve order): oArrayNew = Array(Set(oArray))] UFL: Array.FreqCount [return a map/dictionary][frequency table, preserve order] AutoHotkey: ___ C++: for (const auto& vValue : oArray) oMap[vValue]++ [also: for (const auto& vValue : oArray) oMap[vValue] = oMap.count(vValue) ? oMap[vValue]+1 : 1][beforehand: std::map<std::string,int> oMap][WARNING: if vKey doesn't exist, 'oMap[vKey]++' creates a key with the default value, e.g. 0, then increments it] C#: ___ [e.g. int array: var oDict = oArray.GroupBy(v=>v).Select(g=>new[]{g.Key,g.Count()}).ToDictionary(e=>e[0], e=>e[1])][e.g. string array: var oDict = oArray.GroupBy(v=>v).Select(g=>new KeyValuePair<string,int>(g.Key,g.Count())).ToDictionary(e=>e.Key, e=>e.Value)] Excel: ___ Excel VBA: ___ Java: ___ [e.g. Map<String,Long> oMap = Arrays.stream(oArray).collect(Collectors.groupingBy(e->e, LinkedHashMap::new, Collectors.counting()))][e.g. Map<Integer,Long> oMap = Arrays.stream(oArray).boxed().collect(Collectors.groupingBy(e->e, LinkedHashMap::new, Collectors.counting()))][e.g. List<Integer>/List<String>: var oMap = oList.stream().collect(Collectors.groupingBy(e->e, LinkedHashMap::new, Collectors.counting()))][note (all): preserves order] JavaScript: for (const vValue of oArray) oMap.set(vValue, (oMap.get(vValue)||0) + 1) [beforehand: oMap = new Map()][note: preserves order] Kotlin: oMap = oArray.toList().groupingBy{it}.eachCount() [note: preserves order] PHP: $oMap = array_count_values($oArray) [note: preserves order] Python: for vValue in oList: oDict[vValue] = oDict.get(vValue, 0) + 1 [beforehand: oDict = dict()][note: preserves order][note: collections.Counter() doesn't preserve order] Swift: oDict = oArray.reduce(into:[:]){$0[$1,default:0]+=1} [WARNING: doesn't preserve order] UFL: Array.Max [comparing values according to the array's type, else numerically, return the max] AutoHotkey: vMax := Max(oArray*) C++: auto vMax = *std::max_element(std::begin(oArray), std::end(oArray)) [also: auto vMax = *std::max_element(oVec.begin(), oVec.end())] C#: vMax = oArray.Max() Excel: ___ [can use: MAX()] Excel VBA: ___ [can use: WorksheetFunction.Max()] Java: ___ [e.g. int[]: int vMax = Arrays.stream(oArray).max().getAsInt()][e.g. String[]: var vMax = Arrays.stream(oArray).sorted().skip(oArray.length-1).findFirst().get()][e.g. List<Integer>/List<String>: var vMax = Collections.max(oList)][e.g. int[]: int vMax = Arrays.stream(oArray).summaryStatistics().getMax()] JavaScript: vMax = Math.max(...oArray) Kotlin: vMax = oArray.max() [also: oArray.maxOrNull()] PHP: $vMax = max($oArray) [note: 'standard comparison rules' e.g. 'a non-numeric string will be compared to an int as though it were 0'] Python: vMax = max(oList) Swift: vMax = oArray.max() ?? vDefault UFL: Array.Min [comparing values according to the array's type, else numerically, return the min] AutoHotkey: vMin := Min(oArray*) C++: auto vMin = *std::min_element(std::begin(oArray), std::end(oArray)) [also: auto vMin = *std::min_element(oVec.begin(), oVec.end())] C#: vMin = oArray.Min() Excel: ___ [can use: MIN()] Excel VBA: ___ [can use: WorksheetFunction.Min()] Java: ___ [e.g. int[]: int vMin = Arrays.stream(oArray).min().getAsInt()][e.g. String[]: var vMin = Arrays.stream(oArray).sorted().findFirst().get()][e.g. List<Integer>/List<String>: var vMin = Collections.min(oList)][e.g. int[]: int vMin = Arrays.stream(oArray).summaryStatistics().getMin()] JavaScript: vMin = Math.min(...oArray) Kotlin: vMin = oArray.min() [also: oArray.minOrNull()] PHP: $vMin = min($oArray) [note: 'standard comparison rules' e.g. 'a non-numeric string will be compared to an int as though it were 0'] Python: vMin = min(oList) Swift: vMin = oArray.min() ?? vDefault UFL: (Array.StrMax) [comparing values as strings, return the max][see also: Array.ToStrArray] AutoHotkey: ___ C++: auto vMax = *std::max_element(std::begin(oArray), std::end(oArray)) [also: auto vMax = *std::max_element(oVec.begin(), oVec.end())] C#: vMax = oArray.Select(v=>v.ToString()).Max() [also (if all values strings): var vMax = oArray.Max()][requires: using System.Linq] Excel: ___ Excel VBA: ___ Java: ___ [e.g. String[]: var vMax = Arrays.stream(oArray).sorted().skip(oArray.length-1).findFirst().get()][e.g. List<String>: var vMax = Collections.max(oList)] JavaScript: vMax = oArray.toSorted().pop() Kotlin: vMax = oArray.map{v->v.toString()}.max() [also (if all values strings): vMax = oArray.max()][also: oArray.maxOrNull()] PHP: $vMax = array_reduce($oArray, function($vText1, $vText2) {return (($vText1 == null) ? $vText2 : (strcmp($vText1, $vText2) >= 0 ? $vText1 : $vText2));}) [also (if all values strings): $vMax = max($oArray)] Python: vMax = max(map(str, oList)) [also (if all values strings): vMax = max(oList)] Swift: vMax = oArray.map{String($0)}.max() ?? vDefault [also (if all values strings): vMax = oArray.max() ?? vDefault] UFL: (Array.StrMin) [comparing values as strings, return the min][see also: Array.ToStrArray] AutoHotkey: ___ C++: auto vMin = *std::min_element(std::begin(oArray), std::end(oArray)) [also: auto vMin = *std::min_element(oVec.begin(), oVec.end())] C#: vMin = oArray.Select(v=>v.ToString()).Min() [also (if all values strings): var vMin = oArray.Min()][requires: using System.Linq] Excel: ___ Excel VBA: ___ Java: ___ [e.g. String[]: var vMin = Arrays.stream(oArray).sorted().findFirst().get()][e.g. List<String>: var vMin = Collections.min(oList)] JavaScript: vMin = oArray.toSorted()[0] Kotlin: vMin = oArray.map{v->v.toString()}.min() [also (if all values strings): vMin = oArray.min()][also: oArray.minOrNull()] PHP: $vMin = array_reduce($oArray, function($vText1, $vText2) {return (($vText1 == null) ? $vText2 : (strcmp($vText1, $vText2) <= 0 ? $vText1 : $vText2));}) [also (if all values strings): $vMin = min($oArray)] Python: vMin = min(map(str, oList)) [also (if all values strings): vMin = min(oList)] Swift: vMin = oArray.map{String($0)}.min() ?? vDefault [also (if all values strings): vMin = oArray.min() ?? vDefault] UFL: (Array.Match) [do the contents of 2 arrays match (same items, same order)] AutoHotkey: ___ C++: auto vIsMatch = std::equal(std::begin(oArray1), std::end(oArray1), std::begin(oArray2)) [also: auto vIsMatch = std::equal(oVec1.begin(), oVec1.end(), oVec2.begin())] C#: bool vIsMatch = Enumerable.SequenceEqual(oArray1, oArray2) [also: bool vIsMatch = oArray1.SequenceEqual(oArray2)] Excel: ___ Excel VBA: ___ Java: vIsMatch = Arrays.equals(oArray1, oArray2) [e.g. works on int[]/String[]] JavaScript: ___ Kotlin: vIsMatch = (oArray1 contentEquals oArray2) PHP: $vIsMatch = ($oArray1 === $oArray2) Python: ___ Swift: vIsMatch = (oArray1.count == oArray2.count) && (oArray1 == oArray2) UFL: (Array.MatchUnsorted) [or Array.MatchUnordered][do the contents of 2 arrays match (same items, key order irrelevant)][note: *not* 'MatchAsSet', because sets only contain items once] AutoHotkey: ___ C++: ___ [can use: std::string oArrayCopy1[123]; std::string oArrayCopy2[123]; std::copy(std::begin(oArray1), std::end(oArray1), std::begin(oArrayCopy1)); std::copy(std::begin(oArray2), std::end(oArray2), std::begin(oArrayCopy2)); std::sort(std::begin(oArrayCopy1), std::end(oArrayCopy1)); std::sort(std::begin(oArrayCopy2), std::end(oArrayCopy2)); auto vIsMatch = std::equal(std::begin(oArrayCopy1), std::end(oArrayCopy1), std::begin(oArrayCopy2));][note: replace '123' with the necessary size] C#: bool vIsMatch = Enumerable.SequenceEqual(oArray1.OrderBy(v=>v), oArray2.OrderBy(v=>v)) [also: bool vIsMatch = oArray1.OrderBy(v=>v).SequenceEqual(oArray2.OrderBy(v=>v))] Excel: ___ Excel VBA: ___ Java: ___ [can use (e.g. int[]/String[]): var oArrayCopy1 = oArray1.clone(); var oArrayCopy2 = oArray2.clone(); Arrays.sort(oArrayCopy1); Arrays.sort(oArrayCopy2); var vIsMatch = Arrays.equals(oArrayCopy1, oArrayCopy2);] JavaScript: ___ Kotlin: vIsMatch = (oArray1.sorted().toTypedArray() contentEquals oArray2.sorted().toTypedArray()) PHP: ___ Python: ___ Swift: vIsMatch = (oArray1.count == oArray2.count) && (oArray1.sorted() == oArray2.sorted()) UFL: Array.Map AutoHotkey: ___ C++: std::transform(std::begin(oArray), std::end(oArray), oArrayNew, oFunc) [also: std::transform(oVec.begin(), oVec.end(), std::back_inserter(oVecNew), oFunc)][requires: #include <algorithm>] C#: oArrayNew = oArray.Select(oFunc).ToArray() Excel: ___ Excel VBA: ___ Java: int[] oArrayNew = Arrays.stream(oArray).boxed().mapToInt(oFunc).toArray() [requires: import java.util.*][also: map()] JavaScript: oArrayNew = oArray.map(oFunc) Kotlin: oArrayNew = oArray.map(oFunc).toTypedArray() [also: mapIndexed(): receives the index and the value] PHP: $oArrayNew = array_map($oFunc, $oArray) [WARNING: func then array, unlike reduce/filter][also: array_walk()] Python: oListNew = list(map(oFunc, oList)) Swift: oArrayNew = oArray.map{oFunc($0)} [also: oArray.enumerated().map{oFunc($0,$1)}][note: enumerated(): 'Returns a sequence of pairs (n, x), where n represents a consecutive integer starting at zero and x represents an element of the sequence.'][also: oArray.compactMap()][deprecated: oArray.flatMap()] UFL: Array.Reduce [or Array.Fold/Array.ReduceLeft/Array.FoldLeft] AutoHotkey: ___ C++: int vRet = std::accumulate(std::begin(oArray), std::end(oArray), vInit, oFunc) [also: int vRet = std::accumulate(oVec.begin(), oVec.end(), vInit, oFunc)][requires (std::accumulate): #include <numeric>][also: std::reduce()][also: std::ranges::fold_left()] C#: vRet = oArray.Aggregate(oFunc) Excel: ___ Excel VBA: ___ Java: int vRet = Arrays.stream(oArray).boxed().reduce(oFunc).orElse(0) [requires: import java.util.*] JavaScript: vRet = oArray.reduce(oFunc) Kotlin: vRet = oArray.reduce(oFunc) [also: oArray.fold(oFunc)] PHP: $vRet = array_reduce($oArray, $oFunc) [WARNING: if initial value not specified, it defaults to null] Python: vRet = functools.reduce(oFunc, oList) [requires: import functools] Swift: vRet = oArray.reduce(vInit){oFunc($0,$1)} [also (to use an object as the accumulator, rather than the last return value): e.g. to array: oArray.reduce(into:[]){}, e.g. to dictionary: oArray.reduce(into:[:]){}] UFL: Array.ReduceRight [or Array.FoldRight] AutoHotkey: ___ C++: ___ [can use: std::accumulate()][also: std::ranges::fold_right()] C#: ___ Excel: ___ Excel VBA: ___ Java: ___ JavaScript: oArray.reduceRight(oFunc) Kotlin: oArray.reduceRight(oFunc) [also: oArray.foldRight(oFunc)] PHP: ___ Python: ___ Swift: ___ UFL: Array.Filter [see also: Array.Count/Array.GroupBy/Array.Partition] AutoHotkey: ___ C++: std::copy_if(oVec.begin(), oVec.end(), std::back_inserter(oVecNew), oFunc) [requires (std::copy_if/std::remove_if): #include <algorithm>][also: std::remove_if(oVec.begin(), oVec.end(), oFunc)] C#: oArrayNew = oArray.Where(oFunc).ToArray() Excel: ___ Excel VBA: ___ [note: can use Filter() to list matches(/non-matches) that are a *substring* of a needle, case-sensitive/case-insensitive (integer values are treated as strings)] Java: int[] oArrayNew = Arrays.stream(oArray).boxed().filter(oFunc).mapToInt(v->v).toArray() [requires: import java.util.*] JavaScript: oArrayNew = oArray.filter(oFunc) Kotlin: oArrayNew = oArray.filter(oFunc).toTypedArray() PHP: $oArrayNew = array_values(array_filter($oArray, $oFunc)) [WARNING: array_filter() maintains indexes, use array_values() to reindex an array] Python: oListNew = list(filter(oFunc, oList)) Swift: oArrayNew = oArray.filter{oFunc($0)} UFL: Array.GroupBy [create n separate arrays based on a filter][see also: Array.Filter] AutoHotkey: ___ C++: for (const auto& vValue : oArray) oMap[oFunc].push_back(vValue) [beforehand: std::map<int,std::vector<int>> oMap][requires: #include <vector>][requires: #include <map>][WARNING: if vKey doesn't exist, 'oMap[vKey]' creates a key with the default value, e.g. an empty vector] C#: oDict = oArray.GroupBy(oFunc).ToDictionary(g=>g.Key, g=>g.ToArray()) [requires: using System.Linq][requires: using System.Collections.Generic] Excel: ___ Excel VBA: ___ Java: var oMap = Arrays.stream(oArray).boxed().collect(Collectors.groupingBy(oFunc)) [also: var oMap = oList.collect(Collectors.groupingBy(oFunc))][requires: import java.util.stream.*] JavaScript: ___ [note: some browsers support: 'oMap = Map.groupBy(oArray, oFunc)' and 'oObj = Object.groupBy(oArray, oFunc)'] Kotlin: oMap = oArray.groupBy{oFunc(it)} PHP: ___ [can use: foreach ($oArray as $vValue) $oMapNew[$oFunc($vValue)][] = $vValue][WARNING: '$oMap[$vKey][] = $vValue' creates an array if it doesn't exist, and pushes][beforehand: $oMapNew = []] Python: for k,g in groupby(oList, oFunc): oGroups.append(list(g)) [beforehand: oList = sorted(oList, key=oFunc)][beforehand: oGroups = []][requires: from itertools import groupby] Swift: oDict = Dictionary(grouping:oArray, by:oFunc) UFL: (Array.Partition) [create 2 separate arrays based on a filter][see also: Array.Filter] AutoHotkey: ___ C++: auto oPivot = std::partition(std::begin(oArray), std::end(oArray), oFunc) [also: auto oPivot = std::partition(oVec.begin(), oVec.end(), oFunc)][requires: #include <vector>][requires: #include <algorithm>][note (array): false value count: vPivot = oPivot - oArray][note (vector): false value count: vPivot = oPivot - oVec.begin()] C#: oDict = oArray.GroupBy(oFunc).ToDictionary(g=>g.Key, g=>g.ToArray()) [requires: using System.Linq][requires: using System.Collections.Generic] Excel: ___ Excel VBA: ___ [note: can use Filter() to list matches(/non-matches) that are a *substring* of a needle, case-sensitive/case-insensitive (integer values are treated as strings)] Java: var oMap = Arrays.stream(oArray).boxed().collect(Collectors.partitioningBy(oFunc)) [also: var oMap = oList.stream().collect(Collectors.partitioningBy(oFunc))][requires: import java.util.stream.*] JavaScript: ___ [note: some browsers support: 'oMap = Map.groupBy(oArray, oFunc)' and 'oObj = Object.groupBy(oArray, oFunc)'] Kotlin: (oArray1, oArray2) = oArray.partition{oFunc(it)} [also: oMap = oArray.groupBy{oFunc(it)}] PHP: ___ [can use: foreach ($oArray as $vValue) $oMapNew[$oFunc($vValue)][] = $vValue][WARNING: '$oMap[$vKey][] = $vValue' creates an array if it doesn't exist, and pushes][beforehand: $oMapNew = []] Python: for k,g in groupby(oList, oFunc): oDict[k] = list(g) [beforehand: oList = sorted(oList, key=oFunc)][beforehand: oDict = {}][requires: from itertools import groupby] Swift: vPivot = oArray.partition(by:oFunc) [note: puts non-matches at start (before pivot) and matches at end (including pivot)][WARNING: unstable sort (items are randomly shuffled)][e.g. oNonMatch = oArray[..<vPivot].sorted()][e.g. oMatch = oArray[vPivot...].sorted()] UFL: Array.Zip [combine multiple arrays (of equal length) into on array of 'tuple' arrays, the first 'tuple' contains the first element of each input array][e.g. 'oArray1 = ["a1", "a2", "a3"]'] AutoHotkey: ___ C++: std::transform(oVec1.begin(), oVec1.end(), oVec2.begin(), std::back_inserter(oVecNew), [](const auto&v1, const auto&v2) {return std::vector<std::string>{v1,v2};}) [note: zips 2 vectors into a vector of vectors] C#: var oArrayNew = oArray1.Zip(oArray2, (v1,v2)=>(v1,v2)).Zip(oArray3, (o,v)=>new String[]{o.v1,o.v2,v}).ToArray() [requires: using System.Linq] Excel: ___ Excel VBA: ___ Java: String[][] oArrayNew = IntStream.range(0, oArray1.length).mapToObj(i->new String[]{oArray1[i],oArray2[i],oArray3[i]}).collect(Collectors.toList()).toArray(String[][]::new) [also (for lists): List<List<String>> oArrayNew = IntStream.range(0, oArray1.length).mapToObj(i->Arrays.asList(oArray1[i],oArray2[i],oArray3[i])).collect(Collectors.toList())][requires (IntStream/Collectors): import java.util.stream.*] JavaScript: oArrayNew = oArray1.map((v,k)=>[v,oArray2[k],oArray3[k]]) Kotlin: oArrayNew = oArray1.mapIndexed{k,v->listOf(v,oArray2[k],oArray3[k])} [also (for 2 arrays only): oArrayNew = oArray1.zip(oArray2)] PHP: $oArrayNew = array_map(null, $oArray1, $oArray2, $oArray3) Python: oListNew = list(zip(oList1, oList2, oList3)) Swift: oArrayNew = zip(oArray1, zip(oArray2, oArray3)).map{[$0,$1.0,$1.1]} [note: for tuples, use '($0,$1.0,$1.1)' instead][also (for 2 input arrays only, and for pairs): oArrayNew = zip(oArray1, oArray2).map{[$0,$1]}][note: for tuples, remove '.map{[$0,$1]}'] UFL: Array.SetMultOverwrite [array overwrite/combine, overwrite/add values based on array/map/entries][e.g. oEntries = [[3,"d"]], contains 1 entry, it would set the value of key 3 to 'd', throwing if the array was too small] AutoHotkey: ___ C++: ___ C#: ___ Excel: ___ Excel VBA: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: $oArray1 = array_replace($oArray1, $oArray2, $oArray3) [note: array_replace() overwrites keys][WARNING: array_merge() appends index keys (and overwrites keys with string names)] Python: ___ Swift: ___ UFL: Array.SetMultIfAbsent [or Array.SetMultNoOverwrite][array combine, add values, if the key doesn't already exist, based on array/map/entries (add only, don't overwrite)][e.g. oEntries = [[3,"d"]], would set the value of key 3 to 'd', if key 3 'didn't exist', throwing if the array was too small] AutoHotkey: ___ C++: ___ C#: ___ Excel: ___ Excel VBA: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: $oArray1 += $oArray2 [note: assuming 2 arrays that satisfy array_is_list(), $oArray1 would only be modified if $oArray2 was longer ($oArray1 would receive the last keys of $oArray2)] Python: ___ Swift: ___ UFL: Array.Default [define the default value returned when an element with no value is requested] AutoHotkey: oArray.Default := vValue C++: ___ C#: ___ Excel: ___ Excel VBA: ___ [note: array of type Variant/Integer/Double/String initialised with Empty/0/0/"" respectively] Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ Swift: ___ [can use: vValue = oArray[vKey] ?? vDefault][can use (to fill in blanks): oArray = oArray.map{$0 ?? vDefault}] UFL: (Array.JoinCodepoints) [e.g. an array of chars (as strings), join UTF-16 surrogate pairs (i.e. for some adjacent keys, 2 keys become 1)] AutoHotkey: ___ C++: ___ C#: ___ Excel: ___ Excel VBA: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ Swift: ___ UFL: (Array.SplitCodepoints) [e.g. an array of chars (as strings), split UTF-16 surrogate pairs (i.e. for some keys, 1 key becomes 2)] AutoHotkey: ___ C++: ___ C#: ___ Excel: ___ Excel VBA: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ Swift: ___ UFL: (Array.ToMap) [i.e. indexes become key names, values become values] AutoHotkey: ___ C++: for (int i=0; i<sizeof(oArray)/sizeof(oArray[0]); i++) oMap[i] = oArray[i] [beforehand: std::map<int,std::string> oMap] C#: var oDict = oArray.Select((v,k)=>new{Key=k,Value=v}).ToDictionary(e=>e.Key, e=>e.Value) Excel: ___ Excel VBA: ___ Java: for (int i=0; i<oArray.length; i++) oMap.put(i, oArray[i]) [beforehand: LinkedHashMap<Integer,String> oMap = new LinkedHashMap()] JavaScript: new Map(...[oArray.entries()]) Kotlin: oMap = oArray.mapIndexed{k,v->k to v!!}.toMap() PHP: $oMap = $oArray [note: this creates a copy of the 'array' (the PHP array is a linear and associative array)][note (to get integer keys only): $oArray = array_filter($oArray, fn($v,$k)=>is_int($k), ARRAY_FILTER_USE_BOTH)] Python: oDict = {k:v for k,v in enumerate(oList)} Swift: oDict = Dictionary(uniqueKeysWithValues:oArray.enumerated().map{($0,$1)}) UFL: (Array.ToObject) [i.e. indexes become property names, values become values] AutoHotkey: ___ C++: ___ C#: foreach (var oEntry in oArray.Select((v,k)=>new KeyValuePair<string,object>(k.ToString(),v))) ((IDictionary<string,object>)oObj).Add(oEntry) Excel: ___ Excel VBA: ___ Java: ___ [can use: for (Field oField : oObj.getClass().getFields())][note: property/value: oField.getName(), oField.get(oObj)][note: get()/set() must be within a try block][requires: import java.lang.reflect.Field][note: to modify an existing value: oField.set(oObj, vValue)] JavaScript: oObj = {...oArray} [also: oObj = Object.assign({}, oArray)] Kotlin: ___ PHP: $oObj = (object)$oArray Python: oObj = SimpleNamespace(**{str(k):v for k,v in enumerate(oList)}) Swift: ___ UFL: (Array.ToBuffer) [array of integers to binary data buffer] AutoHotkey: ___ C++: for (int i=0; i<vSize; i++) oBuf[i] = (unsigned char)oArray[i] [beforehand: unsigned char* oBuf = new unsigned char[vSize]] C#: byte[] oBuf = oArray.Select(v=>(byte)v).ToArray() Excel: ___ Excel VBA: ___ Java: for (int i=0; i<oArray.length; i++) oBuf[i] = (byte)oArray[i] [beforehand: byte[] oBuf = new byte[oArray.length]] JavaScript: oBuf = Uint8Array.from(oArray) [also: oBuf = new Uint8Array(oArray.length)] Kotlin: oBuf = ByteArray(oArray.size){k->oArray[k]!!.toByte()} [note: the ByteArray constructor takes a size and an int-to-byte function: <init>(size: Int, init: (Int) -> Byte)][also: oBuf = oArray.map{it.toByte()}.toByteArray()] PHP: ___ Python: oBuf = bytearray(oList) Swift: oBuf = [UInt8](repeating:0, count:oArray.count).enumerated().map{oArray[$0.0]} [note: failed with $0] UFL: Array.ToVector AutoHotkey: ___ C++: ___ [e.g. int array: std::vector<int> oVec(std::begin(oArray), std::end(oArray))][e.g. string array: std::vector<std::string> oVec(std::begin(oArray), std::end(oArray))][requires: #include <vector>] C#: ___ Excel: ___ Excel VBA: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ Swift: ___ UFL: Array.FromVector [or Vector.ToArray] AutoHotkey: ___ C++: std::copy(oVec.begin(), oVec.end(), oArray) [also: for (int i=0; i<oVec.size(); i++) oArray[i] = oVec[i]][beforehand (string array): auto* oArray = new std::string[oVec.size()]][beforehand (int array): auto* oArray = new int[oVec.size()]] C#: ___ Excel: ___ Excel VBA: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ Swift: ___ UFL: Array.ToList AutoHotkey: ___ C++: ___ [e.g. int array: std::list<int> oList(std::begin(oArray), std::end(oArray))][e.g. string array: std::list<std::string> oList(std::begin(oArray), std::end(oArray))][requires: #include <list>] C#: var oList = oArray.ToList() Excel: ___ Excel VBA: ___ Java: ___ [e.g. int array: var oList = Arrays.stream(oArray).boxed().collect(Collectors.toList())][e.g. string array: var oList = Arrays.asList(oArray)][also: string array: var oList = Arrays.stream(oArray).collect(Collectors.toList())][also: string array: var oList = new ArrayList<String>(Arrays.asList(oArray))][WARNING: e.g. for String[]/Integer[] (but not int[]), if do 'oList = Arrays.asList(oArray)', modifying oList or oArray modifies both][WARNING: e.g. for int[], if do 'oList = Arrays.asList(oArray)', oList contains 1 int[], not 0 or more ints] JavaScript: ___ Kotlin: var oList = oArray.toList() [also: var oList = oArray.toMutableList()] PHP: ___ Python: ___ Swift: ___ UFL: Array.FromList [or List.ToArray] AutoHotkey: ___ C++: std::copy(oList.begin(), oList.end(), oArray) [beforehand (string array): auto* oArray = new std::string[oList.size()]][beforehand (int array): auto* oArray = new int[oList.size()]] C#: var oArray = oList.ToArray() Excel: ___ Excel VBA: ___ Java: ___ [e.g. int[] oArray = oList.stream().mapToInt(v->v).toArray()][e.g. String[] oArray = oList.toArray(new String[0])][note: 'String[0]' is an optimisation (alternatively: 'String[oArray.length]')] JavaScript: ___ Kotlin: oArray = oList.toTypedArray() PHP: ___ Python: ___ Swift: ___ UFL: (Array.ToStrArray) [int array to string array] AutoHotkey: ___ C++: for (int i=0; i<sizeof(oArray)/sizeof(oArray[0]); i++) oArrayNew[i] = std::to_string(oArray[i]) [e.g. int array to std::string array] C#: oArrayNew = oArray.Select(v=>v.ToString()).ToArray() Excel: ___ Excel VBA: ___ Java: for (int i=0; i<oArray.length; i++) oArrayNew[i] = "" + oArray[i] [beforehand: var oArrayNew = new String[oArray.length]][also: String[] oArrayNew = Arrays.stream(oArray).mapToObj(String::valueOf).toArray(String[]::new)][also: String[] oArrayNew = Arrays.stream(oArray).mapToObj(Integer::toString).toArray(String[]::new)][also: var oListNew = oList.stream().map(Object::toString).collect(Collectors.toList())] JavaScript: oArrayNew = oArray.map(String) [also: oArrayNew = oArray.map(v=>String(v))] Kotlin: oArrayNew = oArray.map{it.toString()}.toTypedArray() [also: oArrayNew = oArray.map{v->v.toString()}.toTypedArray()] PHP: $oArrayNew = array_map("strval", $oArray) [also: $oArrayNew = array_map(fn($v)=>strval($v), $oArray)] Python: oListNew = list(map(str, oList)) [also: oListNew = list(map(lambda v:str(v), oList))] Swift: oArrayNew = oArray.map(String.init) [also: oArrayNew = oArray.map{String($0)}] UFL: (Array.ToIntArray) [string array to int array] AutoHotkey: ___ C++: for (int i=0; i<sizeof(oArray)/sizeof(oArray[0]); i++) oArrayNew[i] = std::stoi(oArray[i]) [e.g. std::string array to int array] C#: oArrayNew = oArray.Select(v=>Int32.Parse(v)).ToArray() Excel: ___ Excel VBA: ___ Java: for (int i=0; i<oArray.length; i++) oArrayNew[i] = Integer.parseInt(oArray[i]) [beforehand: var oArrayNew = new String[oArray.length]][also: int[] oArrayNew = Stream.of(oArray).mapToInt(Integer::parseInt).toArray()][also: int[] oArrayNew = Arrays.stream(oArray).mapToInt(Integer::parseInt).toArray()][also: var oListNew = oList.stream().mapToInt(Integer::parseInt).boxed().collect(Collectors.toList())] JavaScript: oArrayNew = oArray.map(v=>parseInt(v)) [WARNING: doesn't work because the key index is passed as the radix: oArray.map(parseInt)] Kotlin: oArrayNew = oArray.map{it.toInt()}.toTypedArray() [also: oArrayNew = oArray.map{v->v.toInt()}.toTypedArray()] PHP: $oArrayNew = array_map("intval", $oArray) [also: $oArrayNew = array_map(fn($v)=>intval($v), $oArray)] Python: oListNew = list(map(int, oList)) [also: oListNew = list(map(lambda v:int(v), oList))] Swift: oArrayNew = oArray.compactMap(Int.init) [also: oArrayNew = oArray.compactMap{Int($0)}] Section: Map Methods UFL: Map.Keys AutoHotkey: oKeys := [oMap*] C++: for (const auto& [vKey, _] : oMap) oKeys.push_back(vKey) [beforehand: std::vector<std::string> oKeys][beforehand (also): oKeys.reserve(oMap.size())] C#: var oKeys = oDict.Keys.ToArray() Excel: ___ Excel VBA: ___ Java: String[] oKeys = oMap.keySet().toArray(new String[oMap.size()]) JavaScript: oKeys = oMap.keys() Kotlin: oKeys = oMap.keys PHP: $oKeys = array_keys($oMap) Python: oKeys = list(oDict) [also: oDict.keys()] Swift: oKeys = oDict.keys UFL: Map.Values AutoHotkey: oValues := [oMap.__Enum(2).Bind(&_)*] C++: for (const auto& [_, vValue] : oMap) oValues.push_back(vValue) [beforehand: std::vector<std::string> oValues][beforehand (also): oValues.reserve(oMap.size())] C#: var oValues = oDict.Values.ToArray() Excel: ___ Excel VBA: ___ Java: String[] oValues = oMap.values().toArray(new String[oMap.size()]) JavaScript: oValues = oMap.values() Kotlin: oValues = oMap.values PHP: $oValues = array_values($oMap) Python: oValues = oDict.values() Swift: oValues = oDict.values UFL: Map.Entries [or Map.ToEntries][map to entries (key-value pairs)] AutoHotkey: ___ C++: for (const auto& [vKey, vValue] : oMap) oEntries.push_back({vKey, vValue}) [beforehand: std::vector<std::vector<std::string>> oEntries][beforehand (also): oEntries.reserve(oMap.size())][also (to handle values of different types): std::pair] C#: string[][] oEntries = oDict.Select(e=>new[]{e.Key,e.Value}).ToArray() Excel: ___ Excel VBA: ___ Java: String[][] oEntries = oMap.entrySet().stream().map(e->new String[]{e.getKey(),e.getValue()}).toArray(String[][]::new) JavaScript: oEntries = oMap.entries() Kotlin: oEntries = oMap.entries PHP: foreach ($oMap as $vKey=>$vValue) array_push($oEntries, [$vKey, $vValue]) [beforehand: $oEntries = []][also: $oEntries = array_map(function($oKey) use ($oMap) {return [$oKey, $oMap[$oKey]];}, array_keys($oMap))] Python: oEntries = oDict.items() Swift: oEntries = oDict.keys.map{[$0,oDict[$0]!]} UFL: Map.Count AutoHotkey: vCount := oMap.Count C++: vCount = oMap.size() C#: vCount = oDict.Count Excel: ___ Excel VBA: vCount = oColl.Count Java: vCount = oMap.size() JavaScript: vCount = oMap.size Kotlin: vCount = oMap.size [also: oMap.count()] PHP: $vCount = count($oMap) [also: sizeof($oMap)] Python: vCount = len(oDict) Swift: vCount = oDict.count UFL: Map.Has [or Map.HasKey] AutoHotkey: vHasKey := oMap.Has(vKey) C++: vHasKey = oMap.count(vKey) [note: the 1-param version (overload) acts as a has-key method, returning 1 or 0] C#: vHasKey = oDict.ContainsKey(vKey) Excel: ___ Excel VBA: ___ [can use: 'Call oColl.Item(vKey)' with 'On Error GoTo', i.e. if it throws, the key doesn't exist] Java: vHasKey = oMap.containsKey(vKey) JavaScript: vHasKey = oMap.has(vKey) Kotlin: vHasKey = oMap.contains(vKey) PHP: $vHasKey = array_key_exists($vKey, $oMap) Python: vHasKey = vKey in oDict [inverse: vKey not in oDict] Swift: vHasKey = oDict.keys.contains(vKey) [also: vHasKey = (oDict[vKey] != nil)] UFL: Map.Get [or Map[Key]] AutoHotkey: vValue := oMap[vKey] [also: vValue := oMap.Get(vKey)] C++: vValue = oMap[vKey] [WARNING: if vKey doesn't exist, 'vValue = oMap[vKey]' creates a key with the default value, e.g. 0/blank string] C#: vValue = oDict[vKey] Excel: ___ Excel VBA: vValue = oColl.Item(vKey) [also: oColl.Item(vIndex) / oColl(vKey) / oColl(vIndex)][WARNING: it is not possible to get a list of a collection's key names] Java: vValue = oMap.get(vKey) JavaScript: vValue = oMap.get(vKey) Kotlin: vValue = oMap.get(vKey) PHP: $vValue = $oMap[$vKey] Python: vValue = oDict[vKey] Swift: vValue = oDict[vKey]! UFL: Map.GetOrDefault [if key non-existent/null, provide default (deviations from this are noted)] AutoHotkey: vValue := oMap.Get(vKey, vDefault) C++: ___ C#: vValue = oDict.GetValueOrDefault(vKey, vDefault) [WARNING: returns null if value is null][note: if default omitted, the defaults for int/double/string are 0/0/"" respectively][also: oDict[vKey] ?? vDefault][WARNING: oDict[vKey] throws if key doesn't exist] Excel: ___ Excel VBA: ___ Java: vValue = oMap.getOrDefault(vKey, vDefault) [WARNING: returns null if value is null][also (appears to give the same results, except it returns default rather than null): Optional.ofNullable(oMap.get(vKey)).orElse(vDefault)] JavaScript: vValue = oMap.get(vKey) ?? vDefault [note: returns default if value is null/undefined] Kotlin: vValue = oMap.getOrElse(vKey, oFunc) [e.g. oMap.getOrElse(vKey, {vDefault})][e.g. oMap.getOrElse(vKey){vDefault}][note (unlike arrays): returns default if value is null][also (appears to give the same results): oMap[vKey] ?: vDefault][note: oMap[vKey] returns null if key doesn't exist] PHP: $vValue = $oMap[$vKey] ?? $vDefault Python: vValue = oDict.get(vKey, vDefault) [WARNING: returns None if value is None] Swift: vValue = oDict[vKey, default:vDefault] [WARNING: returns optional nil if value is optional nil][also: vValue = oDict[vKey] ?? vDefault][note: both approaches appear to give the same results][note (both): returns default if key doesn't exist][note: oDict[vKey] returns nil if key doesn't exist] UFL: Map.Set [or Map[Key]] AutoHotkey: oMap[vKey] := vValue [also: oMap.Set(vKey, vValue) and oMap.update()] C++: oMap[vKey] = vValue C#: oDict[vKey] = vValue Excel: ___ Excel VBA: Call oColl.Add(vValue, vKey) [WARNING: value then key][WARNING: key names are *case-insensitive* strings][note: key names are optional, however, every key has a 1-based index][note: to 'modify' a value you use Remove then Add (the key order can be maintained via Add's Before/After params)] Java: oMap.put(vKey, vValue) JavaScript: oMap.set(vKey, vValue) Kotlin: oMap.set(vKey, vValue) [also: oMap.put(vKey, vValue)] PHP: $oMap[$vKey] = $vValue Python: oDict[vKey] = vValue Swift: oDict[vKey] = vValue UFL: Map.Swap [swap 2 elements] AutoHotkey: ___ C++: std::swap(oMap[vKey1], oMap[vKey2]) [also: std::swap(oMap.at(vKey1), oMap.at(vKey2))][WARNING: if vKey doesn't exist, 'oMap[vKey]' creates a key with the default value, e.g. 0/blank string] C#: (oDict[vKey1], oDict[vKey2]) = (oDict[vKey2], oDict[vKey1]) [note: destructuring assignment] Excel: ___ Excel VBA: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: [$oMap[$vKey1], $oMap[$vKey2]] = [$oMap[$vKey2], $oMap[$vKey1]] [note: destructuring assignment] Python: oDict[vKey1], oDict[vKey2] = oDict[vKey2], oDict[vKey1] [note: destructuring assignment] Swift: (oDict[vKey1], oDict[vKey2]) = (oDict[vKey2], oDict[vKey1]) [note: destructuring assignment][note: swap() fails with 'overlapping accesses' error: swap(&oDict[vKey1], &oDict[vKey2])] UFL: Map.Delete AutoHotkey: oMap.Delete(vKey) C++: oMap.erase(vKey) C#: oDict.Remove(vKey) Excel: ___ Excel VBA: oColl.Remove(vKey) [also: oColl.Remove(vIndex)] Java: oMap.remove(vKey) JavaScript: oMap.delete(vKey) Kotlin: oMap.remove(vKey) PHP: $oMap[$vKey] = null [also: unset($oMap[$vKey])] Python: del oDict[vKey] [also: oDict.pop(vKey) and oDict.popitem(vKey)] Swift: oDict[vKey] = nil UFL: Map.Clear AutoHotkey: oMap.Clear() C++: oMap.clear() C#: oDict.Clear() Excel: ___ Excel VBA: Set oColl = New Collection Java: oMap.clear() JavaScript: oMap.clear() Kotlin: oMap.clear() PHP: $oMap = [] [also: array_splice($oMap, 0, count($oMap))][note: appears to work even if the map has no '0' key] Python: oDict.clear() Swift: oDict.removeAll() UFL: Map.Clone [or Map.Copy][copy the entire map] AutoHotkey: oMapNew := oMap.Clone() C++: std::map<std::string,std::string> oMapNew = oMap [WARNING: this copies the object, not a reference] C#: var oDictNew = new Dictionary<string,string>(oDict) Excel: ___ Excel VBA: ___ [note: 'Set oCollNew = oColl' creates a reference, unlike arrays, where 'Set oArrayNew = oArray' is invalid, and 'oArrayNew = oArray' clones the array] Java: var oMapNew = new LinkedHashMap(oMap) JavaScript: oMapNew = new Map(oMap) Kotlin: oMapNew = oMap.toMutableMap() [also: oMapNew = oMap.toMap()] PHP: $oMapNew = $oMap [WARNING: this copies the object, not a reference] Python: oDictNew = oDict.copy() Swift: oDictNew = oDict [WARNING: this copies the object, not a reference] UFL: Map.FromEntries [or Entries.ToMap][create a map from an array of entries, each entry is an array containing a key and a value][e.g. 'oEntries = [["k1","v1"], ["k2","v2"], ["k3","v3"]]'] AutoHotkey: ___ C++: ___ [e.g. oMap.insert({{"k1","v1"}, {"k2","v2"}, {"k3","v3"}})][e.g. oMap.insert(oEntries.begin(), oEntries.end())][beforehand: std::map<std::string,std::string> oMap][beforehand (also): std::pair<std::string,std::string> oEntries[] = {{"k1","v1"}, {"k2","v2"}, {"k3","v3"}}] C#: var oDict = oEntries.ToDictionary(e=>e[0], e=>e[1]) Excel: ___ Excel VBA: ___ Java: LinkedHashMap<String,String> oMap = Arrays.stream(oEntries).collect(LinkedHashMap::new, (a,e)->a.put(e[0],e[1]), Map::putAll) [also: for (String[] e : oEntries) oMap.put(e[0], e[1])][e.g. LinkedHashMap<String,String> oMap = new LinkedHashMap()][e.g. String[][] oEntries = {{"k1","v1"},{"k2","v2"},{"k3","v3"}}][also: Map<String,String> oMap = IntStream.range(0, oEntries.length).boxed().collect(Collectors.toMap(i->oEntries[i][0], i->oEntries[i][1]))] JavaScript: oMap = new Map(oEntries) Kotlin: oMap = oEntries.map{Pair(it[0],it[1])}.toMap() [also: oMap = oEntries.map{e->Pair(e[0],e[1])}.toMap()] PHP: array_reduce($oEntries, function($vAccum, $oEntry) use (&$oMap) {$oMap[$oEntry[0]] = $oEntry[1];}) [beforehand: $oMap = []] Python: oDict = dict(oEntries) Swift: oDict = Dictionary(uniqueKeysWithValues:oEntries.map{($0[0],$0[1])}) [note: failed with $0 and $1] UFL: Map.FromKeysValues [create a map by combining a key array and a value array (of equal length)] AutoHotkey: ___ C++: ___ [can use: std::map::insert() multiple times] C#: var oDict = oKeys.Zip(oValues, (k,v)=>new{k,v}).ToDictionary(e=>e.k, e=>e.v) [also: var oDict = Enumerable.Range(0, oKeys.Length).ToDictionary(i=>oKeys[i], i=>oValues[i])][requires: using System.Linq] Excel: ___ Excel VBA: ___ Java: Map<String,String> oMap = IntStream.range(0, oKeys.length).boxed().collect(Collectors.toMap(i->oKeys[i], i->oValues[i])) JavaScript: oMap = new Map(oKeys.map((v,k)=>[v,oValues[k]])) [note: where v is a key name, and k is an array index] Kotlin: oMap = oKeys.zip(oValues).toMap() PHP: $oMap = array_combine($oKeys, $oValues) Python: oDict = dict(zip(oKeys, oValues)) Swift: Dictionary(uniqueKeysWithValues:zip(oKeys, oValues)) UFL: Map.SetMultOverwrite [map overwrite/combine, overwrite/add values based on (array)/map/entries][i.e. an array consists of index-value pairs to overwrite][see also: Map.FromEntries] AutoHotkey: oMap.Set(vKey1,vValue1, vKey2,vValue2, vKey3,vValue3) C++: ___ [can use: for (const auto& [vKey, vValue] : oEntries) oMap[vKey] = vValue] C#: ___ Excel: ___ Excel VBA: ___ Java: oMap1.putAll(oMap2) JavaScript: oMap1 = new Map([...oMap1, ...oMap2, ...oMap3]) Kotlin: oMap1 += oMap2 [WARNING: unlike PHP, this overwrites keys] PHP: $oMap1 = array_replace($oMap1, $oMap2, $oMap3) [also: $oMap1 = array_merge($oMap1, $oMap2, $oMap3)][note: array_replace treats all key names consistently, array_merge uses special handling for numeric keys] Python: oDict1.update(oDict2) [also: oDict1.update(oEntries)][also: oDict1 |= oDict2][also: oDict1 = {**oDict1, **oDict2, **oDict3}] Swift: oDict1 = oDict1.merging(oDict2){(_,v2) in v2} [note: '{(_,v2) in v2}': it receives 2 values and returns 1] UFL: Map.SetMultIfAbsent [or Map.SetMultNoOverwrite][map combine, add values, if the key doesn't already exist, based on (array)/map/entries (add only, don't overwrite)][see also: Map.FromEntries] AutoHotkey: ___ C++: ___ [e.g. oMap.insert({{"k1","v1"}, {"k2","v2"}, {"k3","v3"}})][e.g. oMap.insert(oEntries.begin(), oEntries.end())] C#: ___ Excel: ___ Excel VBA: ___ Java: oMap2.forEach(oMap1::putIfAbsent) JavaScript: ___ Kotlin: oMap1 += oMap2 - oMap1.keys PHP: $oMap1 += $oMap2 [note: unlike Kotlin, this *doesn't* overwrite keys] Python: ___ [can use: oDictCopy = oDict1.copy(); oDict1.update(oDict2); oDict1.update(oDictCopy)] Swift: oDict1 = oDict1.merging(oDict2){(v1,_) in v1} [note: '{(v1,_) in v1}': it receives 2 values and returns 1] UFL: Map.Flip [flip keys/values][assumes no duplicates amongst values] AutoHotkey: ___ C++: for (auto e = oMap.begin(); e != oMap.end(); ++e) oMapNew[e->second] = e->first [beforehand: std::map<std::string,std::string> oMapNew] C#: oDictNew = oDict.ToDictionary(e=>e.Value, e=>e.Key) [requires: using System.Linq][requires: using System.Collections.Generic] Excel: ___ Excel VBA: ___ Java: for (var e : oMap.entrySet()) oMapNew.put(e.getValue(), e.getKey()) [beforehand: LinkedHashMap<String,String> oMapNew = new LinkedHashMap()][also: var oMapNew = oMap.entrySet().stream().collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey))] JavaScript: oMapNew = new Map(Array.from(oMap, e=>e.reverse())) Kotlin: oMapNew = oMap.map{(k,v)->v to k}.toMap() PHP: $oMapNew = array_flip($oMap) Python: oDictNew = {v:k for k,v in oDict.items()} [also: oDictNew = dict((v,k) for k,v in oDict.items())][also: oDictNew = dict(zip(oDict.values(), oDict.keys()))] Swift: oDictNew = Dictionary(uniqueKeysWithValues:oDict.map{($1,$0)}) UFL: Map.MultiFlip [or Map.FlipMulti][flip keys/values][handles duplicates amongst values][key-value pairs to key-array pairs] AutoHotkey: ___ C++: for (const auto& [vKey, vValue] : oMap) oMapNew[vValue].push_back(vKey) [beforehand: std::map<std::string,std::vector<std::string>> oMapNew][requires: #include <vector>][requires: #include <map>][WARNING: if vKey doesn't exist, 'oMap[vKey]' creates a key with the default value, e.g. an empty vector] C#: oDictNew = oDict.GroupBy(e=>e.Value).ToDictionary(g=>g.Key, g=>g.Select(e=>e.Key).ToArray()) [requires: using System.Linq][requires: using System.Collections.Generic] Excel: ___ Excel VBA: ___ Java: var oMapNew = oMap.entrySet().stream().collect(Collectors.groupingBy(Map.Entry::getValue, Collectors.mapping(Map.Entry::getKey, Collectors.toList()))) JavaScript: for (const [k,v] of oMap) oMapNew.has(v) ? oMapNew.get(v).push(k) : oMapNew.set(v, [k]) [beforehand: oMapNew = new Map()] Kotlin: oMapNew = oMap.entries.groupBy({it.value}, {it.key}) [also: oMapNew = oMap.toList().groupBy{it.second}.mapValues{it.value.map{it.first}}] PHP: foreach ($oMap as $vKey=>$vValue) $oMapNew[$vValue][] = $vKey [WARNING: '$oMap[$vKey][] = $vValue' creates an array if it doesn't exist, and pushes][beforehand: $oMapNew = []] Python: for k,v in oDict.items(): oDictNew.setdefault(v, []).append(k) [beforehand: oDictNew = {}][also: for k,v in oDict.items(): oDictNew[v] = oDictNew.get(v, []) + [k]] Swift: oDictNew = Dictionary(oDict.map{($1,[$0])}, uniquingKeysWith:{(v1,v2) in v1+v2}) UFL: Map.Default [define the default value returned when an element with no value is requested][see also: Map.GetOrDefault] AutoHotkey: oMap.Default := vValue C++: ___ C#: ___ Excel: ___ Excel VBA: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ Swift: ___ UFL: (Map.ToObject) AutoHotkey: ___ C++: ___ C#: foreach (var oEntry in oDict) ((IDictionary<string,object>)oObj).Add(oEntry) [beforehand: dynamic oObj = new ExpandoObject()][requires (ExpandoObject): using System.Dynamic] Excel: ___ Excel VBA: ___ Java: ___ [can use: for (var oEntry : oMap.entrySet())][note: oEntry.getKey(), oEntry.getValue()][can use: for (Field oField : oObj.getClass().getFields())][note: property/value: oField.getName(), oField.get(oObj)][note: get()/set() must be within a try block][requires: import java.lang.reflect.Field][note: to modify an existing value: oField.set(oObj, vValue)] JavaScript: oObj = Object.fromEntries(oMap.entries()) Kotlin: ___ PHP: $oObj = (object)$oMap Python: oObj = SimpleNamespace(**oDict) Swift: ___ UFL: (Map.ToIni) [map to ini file string] AutoHotkey: ___ C++: ___ C#: ___ Excel: ___ Excel VBA: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ Swift: ___ UFL: Map.CaseSense [set whether key names are case sensitive/case insensitive] AutoHotkey: oMap.CaseSense := vMode C++: ___ C#: ___ Excel: ___ Excel VBA: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ [note: a related function: array_change_key_case(): 'Changes the case of all keys in an array'] Python: ___ Swift: ___ Section: Object Methods UFL: Object.PropNames [also: Object.OwnPropNames] AutoHotkey: oProps := [oObj.OwnProps()*] C++: ___ C#: var oProps = ((IDictionary<string,object>)oObj).Keys Excel: ___ Excel VBA: ___ Java: ___ [can use: for (Field oField : oObj.getClass().getFields())][note: property/value: oField.getName(), oField.get(oObj)][note: get()/set() must be within a try block][requires: import java.lang.reflect.Field] JavaScript: oProps = Object.keys(oObj) [also: Object.getOwnPropertyNames(oObj)] Kotlin: ___ PHP: $oProps = array_keys(get_object_vars($oObj)) Python: oProps = list(oObj.__dict__) [also: oObj.__dict__.keys()] Swift: oProps = Mirror(reflecting:oObj).children.map{$0.0!} [note: failed with $0] UFL: Object.Values [also: Object.OwnValues] AutoHotkey: oValues := [oObj.OwnProps().Bind(&_,)*] C++: ___ C#: var oValues = ((IDictionary<string,object>)oObj).Values Excel: ___ Excel VBA: ___ Java: ___ [can use: for (Field oField : oObj.getClass().getFields())][note: property/value: oField.getName(), oField.get(oObj)][note: get()/set() must be within a try block][requires: import java.lang.reflect.Field] JavaScript: oValues = Object.values(oObj) Kotlin: ___ PHP: $oValues = array_values(get_object_vars($oObj)) Python: oValues = oObj.__dict__.values() Swift: oValues = Mirror(reflecting:oObj).children.map{$1} UFL: (Object.Entries) [or Object.ToEntries][also: (Object.OwnEntries)] AutoHotkey: ___ C++: ___ C#: string[][] oEntries = ((IDictionary<string,object>)oObj).Select(e=>new[]{e.Key,(string)e.Value}).ToArray() Excel: ___ Excel VBA: ___ Java: ___ [can use: for (Field oField : oObj.getClass().getFields())][note: property/value: oField.getName(), oField.get(oObj)][note: get()/set() must be within a try block][requires: import java.lang.reflect.Field] JavaScript: oEntries = Object.entries(oObj) Kotlin: ___ PHP: foreach (get_object_vars($oObj) as $vProp=>$vValue) array_push($oEntries, [$vProp, $vValue]) [beforehand: $oEntries = []] Python: oEntries = oObj.__dict__.items() Swift: oEntries = Mirror(reflecting:oObj).children.map{[$0!,$1]} UFL: Object.OwnPropCount [also: (Object.PropCount)] AutoHotkey: vCount := ObjOwnPropCount(oObj) C++: ___ [can use (e.g. if all members of the same size, e.g. std::string): e.g. 'vCount = sizeof(oObj)/sizeof(std::string)', e.g. 'vCount = sizeof(MyStruct)/sizeof(std::string)'] C#: vCount = ((IDictionary<string,object>)oObj).Count Excel: ___ Excel VBA: ___ Java: vCount = oObj.getClass().getFields().length JavaScript: vCount = Object.keys(oObj).length [also: Object.getOwnPropertyNames(oObj).length] Kotlin: ___ PHP: $vCount = count(get_object_vars($oObj)) [also: count((array)$oObj)] Python: vCount = len(oObj.__dict__) Swift: vCount = Mirror(reflecting:oObj).children.count UFL: Object.Has [also: Object.HasOwn/HasOwnProp/HasOwnProperty] AutoHotkey: vHasProp := oObj.HasOwnProp(vProp) C++: ___ C#: vHasProp = ((IDictionary<string,object>)oObj).ContainsKey(vProp) Excel: ___ Excel VBA: ___ Java: ___ [can use: for (Field oField : oObj.getClass().getFields())][note: property/value: oField.getName(), oField.get(oObj)][note: get()/set() must be within a try block][requires: import java.lang.reflect.Field] JavaScript: vHasProp = (vProp in oObj) [also: oObj.hasOwn(vProp)][also: oObj.hasOwnProperty(vProp)][note: '(vProp in oObj)' works on all properties, not just own properties] Kotlin: ___ PHP: $vHasProp = property_exists($oObj, $vProp) Python: vHasProp = vProp in oObj.__dict__ [note: inverse: vProp not in oObj.__dict__] Swift: vHasProp = (Mirror(reflecting:oObj).descendant(vProp) != nil) UFL: Object.Get [or Object[Prop]] AutoHotkey: vValue := oObj.%vProp% C++: ___ [e.g. vValue = oObj.MyProp] C#: vValue = ((IDictionary<string,object>)oObj)[vProp] [note: may want to append '.ToString()'] Excel: ___ Excel VBA: ___ Java: ___ [can use: for (Field oField : oObj.getClass().getFields())][note: property/value: oField.getName(), oField.get(oObj)][note: get()/set() must be within a try block][requires: import java.lang.reflect.Field] JavaScript: vValue = oObj[vProp] Kotlin: ___ [e.g. vValue = oObj.MyProp] PHP: $vValue = $oObj->$vProp Python: vValue = oObj.__dict__[vProp] Swift: vValue = Mirror(reflecting:oObj).descendant(vProp)! UFL: Object.GetOrDefault [if property non-existent/null, provide default (deviations from this are noted)] AutoHotkey: ___ C++: ___ C#: vValue = ((IDictionary<string,object>)oObj)[vProp] ?? vDefault [note: may want to append '.ToString()'][note: doesn't work: ((IDictionary<string,object>)oObj).GetValueOrDefault(vProp, vDefault)][WARNING: ((IDictionary<string,object>)oObj)[vProp] throws if property doesn't exist] Excel: ___ Excel VBA: ___ Java: ___ [can use: for (Field oField : oObj.getClass().getFields())][note: property/value: oField.getName(), oField.get(oObj)][note: get()/set() must be within a try block][requires: import java.lang.reflect.Field] JavaScript: vValue = oObj[vProp] ?? vDefault [note: returns default if value is null/undefined] Kotlin: ___ PHP: $vValue = $oObj->$vProp ?? $vDefault Python: vValue = oObj.__dict__.get(vProp, vDefault) [WARNING: returns None if value is None] Swift: vValue = Mirror(reflecting:oObj).descendant(vProp) ?? vDefault [WARNING: returns optional nil if value is optional nil][note: returns default if key doesn't exist] UFL: Object.Set [or Object[Prop]] AutoHotkey: oObj.%vProp% := vValue [also: oObj.DefineProp(vPropName, oDescriptor)][e.g. oObj.MyProp := vValue] C++: ___ [e.g. oObj.MyProp = vValue] C#: ((IDictionary<string,object>)oObj)[vProp] = vValue [e.g. oObj.MyProp = vValue] Excel: ___ Excel VBA: ___ Java: ___ [can use: for (Field oField : oObj.getClass().getFields())][note: property/value: oField.getName(), oField.get(oObj)][note: get()/set() must be within a try block][requires: import java.lang.reflect.Field][note: to modify an existing value: oField.set(oObj, vValue)][e.g. oObj.MyProp = vValue] JavaScript: oObj[vProp] = vValue [e.g. oObj.MyProp = vValue] Kotlin: ___ [e.g. oObj.MyProp = vValue] PHP: $oObj->$vProp = $vValue [e.g. $oObj->MyProp = $vValue] Python: oObj.__dict__[vProp] = vValue [e.g. oObj.MyProp = vValue] Swift: ___ [e.g. oObj.MyProp = vValue] UFL: Object.Swap [swap 2 elements] AutoHotkey: ___ C++: ___ [e.g. std::swap(oObj.MyProp1, oObj.MyProp2)] C#: (((IDictionary<string,object>)oObj)[vProp1], ((IDictionary<string,object>)oObj)[vProp2]) = (((IDictionary<string,object>)oObj)[vProp2], ((IDictionary<string,object>)oObj)[vProp1]) [note: destructuring assignment] Excel: ___ Excel VBA: ___ Java: ___ JavaScript: [oObj[vProp1], oObj[vProp2]] = [oObj[vProp2], oObj[vProp1]] [also: e.g. [oObj.MyProp1, oObj.MyProp2] = [oObj.MyProp2, oObj.MyProp1]][note: destructuring assignment] Kotlin: ___ PHP: [$oObj->$vProp1, $oObj->$vProp2] = [$oObj->$vProp2, $oObj->$vProp1] [note: destructuring assignment] Python: oObj.__dict__[vProp1], oObj.__dict__[vProp2] = oObj.__dict__[vProp2], oObj.__dict__[vProp1] [note: destructuring assignment] Swift: ___ UFL: Object.DeleteProp [or Object.DeleteOwnProp][i.e. reduce the property count by 1] AutoHotkey: oObj.DeleteProp(vProp) C++: ___ C#: ((IDictionary<string,object>)oObj).Remove(vProp) Excel: ___ Excel VBA: ___ Java: ___ [note: to assign null: oObj.MyProp = null] JavaScript: delete oObj[vProp] Kotlin: ___ [note: to assign null: oObj.MyProp = null] PHP: unset($oObj->$vProp) [note: to assign null: $oObj->$vProp = null] Python: del oObj.__dict__[vProp] [also: oObj.__dict__.pop(vProp) and oObj.__dict__.popitem(vProp)] Swift: ___ [note: to assign null: oObj.MyProp = nil] UFL: (Object.DeleteOwnProps) [or Object.Clear][also: (Object.DeleteProps)] AutoHotkey: ___ C++: ___ [note: to reset values to the defaults: 'oObj = {}', also: 'oObj = MyStruct()'] C#: ((IDictionary<string,object>)oObj).Clear() Excel: ___ Excel VBA: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: oObj.__dict__.clear() Swift: ___ [note: to reset values to the defaults: oObj = MyStruct()] UFL: (Object.Clone) [or Object.Copy][copy the entire object][typically a shallow copy] AutoHotkey: oObjNew := oObj.Clone() C++: oObjNew = oObj [WARNING: this copies the object, not a reference] C#: foreach (var oEntry in (IDictionary<string,object>)oObj) ((IDictionary<string,object>)oObjNew).Add(oEntry) [beforehand: dynamic oObjNew = new ExpandoObject()] Excel: ___ Excel VBA: ___ Java: ___ JavaScript: oObjNew = structuredClone(oObj) [also (with caveats): oObjNew = JSON.parse(JSON.stringify(oObj))][also (with caveats): oObjNew = Object.assign({}, oObj)] Kotlin: oObjNew = oObj.copy() PHP: $oObjNew = (object)(array)$oObj [also (to deep copy, with caveats): $oObjNew = unserialize(serialize($oObj))] Python: oObjNew = SimpleNamespace(**oObj.__dict__) [also: oObjNew = SimpleNamespace(**vars(oObj))][also: oObjNew = copy.copy(oObj)][also: oObjNew = copy.deepcopy(oObj)] Swift: oObjNew = oObj [WARNING: this copies the object, not a reference] UFL: (Object.FromEntries) [or Entries.ToObject][create an object from an array of entries, each entry is an array containing a property name and a value][e.g. 'oEntries = [["p1","v1"], ["p2","v2"], ["p3","v3"]]'] AutoHotkey: ___ C++: ___ C#: foreach (var oEntry in oEntries) ((IDictionary<string,object>)oObj)[oEntry[0]] = oEntry[1] [beforehand: dynamic oObj = new ExpandoObject()] Excel: ___ Excel VBA: ___ Java: ___ [can use: for (var oEntry : oEntries)][can use: for (Field oField : oObj.getClass().getFields())][note: property/value: oField.getName(), oField.get(oObj)][note: get()/set() must be within a try block][requires: import java.lang.reflect.Field][note: to modify an existing value: oField.set(oObj, vValue)] JavaScript: oObj = Object.fromEntries(oEntries) Kotlin: ___ PHP: array_reduce($oEntries, function($vAccum, $oEntry) use (&$oMap) {$oMap[$oEntry[0]] = $oEntry[1];}) [beforehand: $oMap = []][afterwards: $oObj = (object)$oMap] Python: oObj = SimpleNamespace(**dict(oEntries)) Swift: ___ UFL: (Object.FromPropsValues) [or Object.FromKeysValues][create an object by combining a property name array and a value array (of equal length)] AutoHotkey: ___ C++: ___ C#: foreach (var i in Enumerable.Range(0, oProps.Length)) ((IDictionary<string,object>)oObj)[oProps[i]] = oValues[i] Excel: ___ Excel VBA: ___ Java: ___ [can use: for (var vValue : oArray)][can use: for (Field oField : oObj.getClass().getFields())][note: property/value: oField.getName(), oField.get(oObj)][note: get()/set() must be within a try block][requires: import java.lang.reflect.Field][note: to modify an existing value: oField.set(oObj, vValue)] JavaScript: oObj = Object.fromEntries(oProps.map((v,k)=>[v,oValues[k]])) [note: where v is a property name, and k is an array index] Kotlin: ___ PHP: $oObj = (object)array_combine($oProps, $oValues) Python: oObj = SimpleNamespace(**dict(zip(oProps, oValues))) Swift: ___ UFL: (Object.SetMultOverwrite) [object overwrite/combine, overwrite/add values based on (array)/object/entries] AutoHotkey: ___ C++: ___ C#: ___ Excel: ___ Excel VBA: ___ Java: ___ [can use: for (var oEntry : oMap.entrySet())][note: oEntry.getKey(), oEntry.getValue()][can use: for (Field oField : oObj.getClass().getFields())][note: property/value: oField.getName(), oField.get(oObj)][note: get()/set() must be within a try block][requires: import java.lang.reflect.Field][note: to modify an existing value: oField.set(oObj, vValue)] JavaScript: oObj = {...oObj1, ...oObj2, ...oObj3} Kotlin: ___ PHP: $oObj1 = (object)array_replace((array)$oObj1, (array)$oObj2, (array)$oObj3) [also: $oObj1 = (object)array_merge((array)$oObj1, (array)$oObj2, (array)$oObj3)][note: array_replace treats all key names consistently, array_merge uses special handling for numeric keys] Python: oObj1.__dict__.update(oObj2.__dict__) Swift: ___ UFL: (Object.SetMultIfAbsent) [or Object.SetMultNoOverwrite][object combine, add values, if the property doesn't already exist, based on (array)/object/entries (add only, don't overwrite)] AutoHotkey: ___ C++: ___ C#: ___ Excel: ___ Excel VBA: ___ Java: ___ [can use: for (var oEntry : oMap.entrySet())][note: oEntry.getKey(), oEntry.getValue()][can use: for (Field oField : oObj.getClass().getFields())][note: property/value: oField.getName(), oField.get(oObj)][note: get()/set() must be within a try block][requires: import java.lang.reflect.Field][note: to modify an existing value: oField.set(oObj, vValue)] JavaScript: ___ Kotlin: ___ PHP: $oObj1 = (object)((array)$oObj1 + (array)$oObj2) [note: unlike Kotlin, this *doesn't* overwrite keys] Python: ___ [can use: oDictCopy = oObj1.__dict__.copy(), oObj1.__dict__.update(oObj2.__dict__), oObj1.__dict__.update(oDictCopy)] Swift: ___ UFL: Object.Flip [flip properties/values][assumes no duplicates amongst values] AutoHotkey: ___ C++: ___ C#: dynamic oObjNew = ((IDictionary<string,object>)oObj).ToDictionary(e=>(string)e.Value, e=>(object)e.Key) Excel: ___ Excel VBA: ___ Java: ___ JavaScript: oObjNew = Object.fromEntries(Object.entries(oObj).map(e=>e.reverse())) [also: oObjNew = Object.fromEntries(Object.entries(oObj).map(([k,v])=>[v,k]))] Kotlin: ___ PHP: $oObjNew = (object)array_flip((array)$oObj) Python: oObjNew = SimpleNamespace(**{v:k for k,v in oObj.__dict__.items()}) Swift: ___ UFL: (Object.MultiFlip) [or Object.FlipMulti][flip properties/values][handles duplicates amongst values][property-value pairs to property-array pairs] AutoHotkey: ___ C++: ___ C#: foreach (var oEntry in ((IDictionary<string,object>)oObj).GroupBy(e=>e.Value).ToDictionary(g=>(string)g.Key, g=>(object)g.Select(e=>e.Key).ToArray())) ((IDictionary<string,object>)oObjNew).Add(oEntry) [beforehand: dynamic oObjNew = new ExpandoObject()] Excel: ___ Excel VBA: ___ Java: ___ [can use: for (Field oField : oObj.getClass().getFields())][note: property/value: oField.getName(), oField.get(oObj)][note: get()/set() must be within a try block][requires: import java.lang.reflect.Field][note: to modify an existing value: oField.set(oObj, vValue)] JavaScript: for (const [p,v] of Object.entries(oObj)) (v in oObjNew) ? oObjNew[v].push(p) : oObjNew[v] = [p] [beforehand: oObjNew = {}] Kotlin: ___ PHP: foreach ($oObj as $vProp=>$vValue) $oObjNew->$vValue[] = $vProp [WARNING: '$oObj->$vProp[] = $vValue' creates an array if it doesn't exist, and pushes][beforehand: $oObjNew = new stdClass()] Python: for k,v in oObj.__dict__.items(): oObjNew.__dict__.setdefault(v, []).append(k) [beforehand: oObjNew = SimpleNamespace()][also: for k,v in oObj.__dict__.items(): oObjNew.__dict__[v] = oObjNew.__dict__.get(v, []) + [k]] Swift: ___ UFL: (Object.Default) [see also: Object.GetOrDefault] AutoHotkey: ___ C++: ___ C#: ___ Excel: ___ Excel VBA: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ Swift: ___ UFL: (Object.ToMap) AutoHotkey: ___ C++: ___ C#: Dictionary<string,string> oDict = ((IDictionary<string,object>)oObj).ToDictionary(e=>e.Key, e=>(string)e.Value) Excel: ___ Excel VBA: ___ Java: ___ [can use: for (Field oField : oObj.getClass().getFields())][note: property/value: oField.getName(), oField.get(oObj)][note: get()/set() must be within a try block][requires: import java.lang.reflect.Field][note: to add to the map: oMap.put(vProp, vValue)][beforehand: LinkedHashMap<String,String> oMap = new LinkedHashMap()] JavaScript: oMap = new Map([...Object.entries(oObj)]) Kotlin: ___ PHP: $oMap = (array)$oObj Python: oObj.__dict__.copy() Swift: oDict = Dictionary(uniqueKeysWithValues:Mirror(reflecting:oObj).children.map{($0!,$1)}) UFL: (Object.ToIni) [object to ini file string] AutoHotkey: ___ C++: ___ C#: ___ Excel: ___ Excel VBA: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ Swift: ___ UFL: (Object.CaseSense) AutoHotkey: ___ C++: ___ C#: ___ Excel: ___ Excel VBA: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ Swift: ___ Section: Range Methods UFL: Range.Length [or Range.Count] AutoHotkey: ___ C++: oRange.size() C#: oRange.Count() Excel: ___ Excel VBA: ___ Java: oRange.count() [also: oRange.summaryStatistics().getCount()][WARNING (count()/getCount()): terminal operation, makes oRange unusable] JavaScript: ___ Kotlin: oRange.count() PHP: count($oRange) [also: sizeof($oRange)] Python: ___ [can use: vCount = functools.reduce(lambda a,b : a+1, oRange, 0)][requires: import functools] Swift: oRange.count UFL: Range.ToArray AutoHotkey: ___ C++: std::iota(oArray, oArray+oRange.size(), oRange.front()) [beforehand: int* oArray = new int[oRange.size()]][also (array of known size): std::iota(std::begin(oArray), std::end(oArray), oRange.front())][beforehand (array of known size: replace '123' with the necessary size): int oArray[123]][requires (std::iota): #include <numeric>][also (vector): std::iota(oVec.begin(), oVec.end(), oRange.front())][beforehand (vector): std::vector<int> oVec(oRange.size())] C#: oArray = oRange.ToArray() Excel: ___ Excel VBA: ___ Java: var oArray = oRange.toArray() [WARNING: terminal operation, makes oRange unusable] JavaScript: ___ Kotlin: oArray = oRange.toList().toTypedArray() PHP: $oArray = $oRange [note: the PHP range is an array] Python: oList = list(oRange) Swift: oArray = Array(oRange) UFL: (Range.Entries) [or Range.ToEntries] AutoHotkey: ___ C++: oEntries.push_back(std::make_pair(i, oRange[i])) [beforehand: std::vector<std::pair<int,int>> oEntries] C#: int[][] oEntries = oRange.Select((v,k)=>new[]{k,v}).ToArray() Excel: ___ Excel VBA: ___ Java: for (int i=0; i<oArray.length; i++) oEntries[i] = new int[]{i, oArray[i]} [beforehand: int[][] oEntries = new int[oArray.length][2]] JavaScript: ___ [can use: oEntries = oRange.entries()][note: where oRange is an array] Kotlin: oEntries = oRange.mapIndexed{k,v->k to v!!}.toMap().entries PHP: foreach ($oRange as $vKey=>$vValue) array_push($oEntries, [$vKey, $vValue]) [beforehand: $oEntries = []][also: $oEntries = array_map(function($oKey) use ($oRange) {return [$oKey, $oRange[$oKey]];}, array_keys($oRange))][note: the PHP range is an array] Python: oEntries = {k:v for k,v in enumerate(oRange)}.items() Swift: oEntries = oRange.enumerated().map{[$0,$1]} UFL: Range.Start AutoHotkey: ___ C++: oRange.front() C#: oRange.First() Excel: ___ Excel VBA: ___ Java: oRange.min().orElse(0) [note: orElse() to unwrap optional value][also: oRange.summaryStatistics().getMin()][WARNING (min()/getMin()): terminal operation, makes oRange unusable] JavaScript: ___ Kotlin: oRange.start PHP: ___ Python: oRange.start Swift: oRange.lowerBound UFL: Range.End AutoHotkey: ___ C++: oRange.back() C#: oRange.Last() Excel: ___ Excel VBA: ___ Java: oRange.max().orElse(0) [note: orElse() to unwrap optional value][also: oRange.summaryStatistics().getMax()][WARNING (max()/getMax()): terminal operation, makes oRange unusable] JavaScript: ___ Kotlin: oRange.endInclusive [deprecated: oRange.endExclusive] PHP: ___ Python: oRange.stop Swift: oRange.upperBound UFL: Range.Step AutoHotkey: ___ C++: ___ C#: ___ Excel: ___ Excel VBA: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: oRange.step Swift: ___ UFL: (Range.Clone) [or Range.Copy] AutoHotkey: ___ C++: auto oRangeNew = oRange [WARNING: this copies the object, not a reference] C#: var oRangeNew = Enumerable.Range(oRange.First(), oRange.Count()) [WARNING: 2nd param is count, not end] Excel: ___ Excel VBA: ___ Java: var oRangeNew = IntStream.rangeClosed(oStats.getMin(), oStats.getMax()) [beforehand (WARNING: terminal operation, makes oRange unusable): var oStats = oRange.summaryStatistics()][note: works on ranges created by both IntStream.range() and IntStream.rangeClosed()][note: the statistics object can be used as often as desired, unlike the range object] JavaScript: ___ Kotlin: oRangeNew = oRange.start..oRange.endInclusive [e.g. works with 1..3 and 1..<4, both of type IntRange] PHP: ___ Python: oRangeNew = range(oRange.start, oRange.stop, oRange.step) Swift: oRangeNew = type(of:oRange).init(uncheckedBounds:(lower:oRange.lowerBound, upper:oRange.upperBound)) [note: confirmed to work with ClosedRange<Int> and Range<Int>] Section: Array.Map Examples UFL: MakeArrowFuncDemo1Param [example arrow function (anonymous function) (lambda function) (closure)] AutoHotkey: MyDouble := vNum => vNum*2 C++: auto MyDouble = [](int vNum) {return vNum*2;} C#: Func<int,int> MyDouble = vNum => vNum*2 Excel: ___ Excel VBA: ___ Java: ToIntFunction<Integer> MyDouble = vNum -> vNum*2 [requires: import java.util.function.*] JavaScript: MyDouble = vNum => vNum*2 Kotlin: MyDouble = {vNum:Int -> vNum*2} PHP: $MyDouble = fn($vNum) => $vNum*2 Python: MyDouble = lambda vNum : vNum*2 Swift: MyDouble: (_ vNum: Int) -> Int = {vNum in vNum*2} UFL: MakeArrowFuncDemo2Param [example arrow function (anonymous function) (lambda function) (closure)] AutoHotkey: MyMul := (vNum1,vNum2) => vNum1*vNum2 C++: auto MyMul = [](int vNum1,int vNum2) {return vNum1*vNum2;} C#: Func<int,int,int> MyMul = (vNum1,vNum2) => vNum1*vNum2 Excel: ___ Excel VBA: ___ Java: BinaryOperator<Integer> MyMul = (vNum1,vNum2) -> vNum1*vNum2 [requires: import java.util.function.*] JavaScript: MyMul = (vNum1,vNum2) => vNum1*vNum2 Kotlin: MyMul = {vNum1:Int,vNum2:Int -> vNum1*vNum2} PHP: $MyMul = fn($vNum1,$vNum2) => $vNum1*$vNum2 Python: MyMul = lambda vNum1,vNum2 : vNum1*vNum2 Swift: MyMul: (_ vNum1:Int, _ vNum2:Int) -> Int = {vNum1,vNum2 in vNum1*vNum2} UFL: Array.MapDemoValuesFuncObject [map values using function object] AutoHotkey: ___ C++: std::transform(oVec.begin(), oVec.end(), std::back_inserter(oVecNew), MyDouble) [also: std::transform(std::begin(oArray), std::end(oArray), oArrayNew, MyDouble)][requires (std::transform): #include <algorithm>] C#: oArrayNew = oArray.Select(MyDouble).ToArray() Excel: ___ Excel VBA: ___ Java: int[] oArrayNew = Arrays.stream(oArray).boxed().mapToInt(MyDouble).toArray() JavaScript: oArrayNew = oArray.map(MyDouble) Kotlin: oArrayNew = oArray.map(MyDouble).toTypedArray() PHP: $oArrayNew = array_map($MyDouble, $oArray) Python: oListNew = list(map(MyDouble, oList)) Swift: oArrayNew = oArray.map(MyDouble) UFL: Array.MapDemoKeysValuesFuncObject [map keys/values using function object] AutoHotkey: ___ C++: ___ [can use: for (int i=0; i<oVec.size(); i++) oVecNew.push_back(MyMul(i, oVec[i]))][also: for (int i=0; i<sizeof(oArray)/sizeof(oArray[0]); i++) oArrayNew[i] = MyMul(i, oArray[i])] C#: oArrayNew = oArray.Select(MyMul).ToArray() Excel: ___ Excel VBA: ___ Java: ___ JavaScript: oArrayNew = oArray.map(MyMul) Kotlin: oArrayNew = oArray.mapIndexed(MyMul).toTypedArray() PHP: $oArrayNew = array_map($MyMul, $oArray, array_keys($oArray)) Python: oListNew = list(map(MyMul, oList, range(len(oList)))) Swift: oArrayNew = oArray.enumerated().map(MyMul) UFL: Array.MapDemoValuesClosure [map values using function object within a closure] AutoHotkey: ___ C++: std::transform(oVec.begin(), oVec.end(), std::back_inserter(oVecNew), [&MyDouble](int v) {return MyDouble(v);}) [also: std::transform(std::begin(oArray), std::end(oArray), oArrayNew, [&MyDouble](int v) {return MyDouble(v);})][note: can replace '[&MyDouble]' with '[MyDouble]'][requires (std::transform): #include <algorithm>] C#: oArrayNew = oArray.Select(v=>MyDouble(v)).ToArray() Excel: ___ Excel VBA: ___ Java: int[] oArrayNew = Arrays.stream(oArray).boxed().mapToInt(v->MyDouble.applyAsInt(v)).toArray() JavaScript: oArrayNew = oArray.map(v=>MyDouble(v)) Kotlin: oArrayNew = oArray.map{MyDouble(it)}.toTypedArray() [also: oArray.map{v->MyDouble(v)}.toTypedArray()] PHP: $oArrayNew = array_map(fn($v)=>$MyDouble($v), $oArray) Python: oListNew = list(map(lambda v:MyDouble(v), oList)) Swift: oArrayNew = oArray.map{MyDouble($0)} UFL: Array.MapDemoKeysValuesClosure [map keys/values using function object within a closure] AutoHotkey: ___ C++: ___ [can use: for (int i=0; i<oVec.size(); i++) oVecNew.push_back(MyMul(i, oVec[i]))][also: for (int i=0; i<sizeof(oArray)/sizeof(oArray[0]); i++) oArrayNew[i] = MyMul(i, oArray[i])] C#: oArrayNew = oArray.Select((v,k)=>MyMul(k,v)).ToArray() Excel: ___ Excel VBA: ___ Java: int[] oArrayNew = IntStream.range(0, oArray.length).boxed().mapToInt(i->MyMul.apply(i,oArray[i])).toArray() JavaScript: oArrayNew = oArray.map((v,k)=>MyMul(v,k)) Kotlin: oArray.mapIndexed{k,v->MyMul(k,v)}.toTypedArray() PHP: $oArrayNew = array_map($MyMul, $oArray, array_keys($oArray), array_keys($oArray)) Python: oListNew = list(map(lambda k,v:MyMul(k,v), oList, range(len(oList)))) [also: oListNew = list(map(lambda e:MyMul(e[0],e[1]), enumerate(oList)))][also: oListNew = [MyMul(k,v) for k,v in enumerate(oList)]] Swift: oArrayNew = oArray.enumerated().map{MyMul($0,$1)} Section: Import/Include Tips The main imports/includes needed for these (and other) code examples: [C++] #include <iostream> //for std::cout //classic types: #include <string> #include <vector> #include <map> #include <ranges> //further types: #include <array> #include <list> #include <sstream> //for std::stringstream #include <unordered_set> //further: #include <algorithm> //for std::copy_if, std::remove_if, std::transform #include <chrono> #include <format> //for std::format #include <functional> //for std::bind #include <numeric> //for std::accumulate #include <random> #include <stdexcept> //for std::exception #include <thread> #include <type_traits> //for std::is_array, std::is_fundamental, std::is_same [C#] using System; using System.Linq; using System.Collections.Generic; using System.Dynamic; //for ExpandoObject //further: using System.Text; //for StringBuilder [Java] import java.util.*; import java.util.stream.*; //further: import java.lang.reflect.Field; import java.util.function.*; [Python] from types import SimpleNamespace import functools //for functools.reduce from itertools import groupby [Swift] import Foundation Language-Specific Notes [general] Array indexes and string character indexes: Be aware of what happens when you go beyond bounds. Possibilities: index below 0 (or below 1 if 1-indexed), treated as min index, invalid index so throws, null returned, treated as negative offset from end. Possibilities: index too large, treated as max index, invalid index so throws, null returned. [C++] There are various functions where these 2 approaches are interchangeable: MyFunc(oArray, oArray+sizeof(oArray)/sizeof(oArray[0])) MyFunc(std::begin(oArray), std::end(oArray)) And where these 2 approaches are interchangeable: MyFunc(oVec.begin(), oVec.end()) MyFunc(std::begin(oVec), std::end(oVec)) E.g. functions: std::accumulate/std::partition/std::transform, std::copy, std::equal, std::fill, std::find, std::max_element/std::min_element, std::reverse/std::shuffle/std::sort. Further functions: std::copy_if/std::remove_if, std::iota. [Java] [int array to Integer array] int[] oArray = {1, 2, 3}; Integer[] oArrayNew = Arrays.stream(oArray).boxed().toArray(Integer[]::new); [Integer array to int array] Integer[] oArray = {1, 2, 3}; int[] oArrayNew = Arrays.stream(oArray).mapToInt(v->v).toArray();