I have an object conf in React:
Object.keys(conf):
0: "ubicacion1"
1: "ubicacion2"
Object.values(conf):
0: "http://www.example1.es:8080"
1: "https://www.example2.es:8443"
How can I work or display each position of the Object?
Thank you
//work
conf.ubicacion1
//or
conf["ubicacion1"]
//log
console.log(conf.ubicacion1)
Related
I have researched a few questions on StackOverflow but couldn't find a relevant answer.
I have a string of array like this:
"[{"insert":"Test"},{"insert":"\n","attributes":{"header":1}},{"insert":"Asdasfff"},{"insert":"\n","attributes":{"list":"bullet"}},{"insert":"Asadsf"},{"insert":"\n","attributes":{"list":"bullet"}},{"insert":"Sfsfsft"},{"insert":"\n","attributes":{"header":2}},{"insert":"Make"},{"insert":"\n","attributes":{"list":"unchecked"}},{"insert":"Back"},{"insert":"\n","attributes":{"list":"checked"}},{"insert":"Ban"},{"insert":"\n","attributes":{"list":"unchecked"}},{"insert":"Fg"},{"insert":"\n","attributes":{"list":"checked"}}]"
and I need to convert it to an array as shown below:
I tried JSON.parse() but it didn't work!
It is because of the \n in your JSON. Here an explanation: https://stackoverflow.com/a/5191059/11749096
function jsonEscape(str) {
return str.replace(/\n/g, "\\\\n").replace(/\r/g, "\\\\r").replace(/\t/g, "\\\\t");
}
var data = `[{"insert":"Test"},{"insert":"\n","attributes": 0}]`;
var dataObj = JSON.parse(jsonEscape(data));
console.log(dataObj);
You have not a string of array, the first and the last double quote must be one quote in your case because when you stringify an array it works like this :
const goo = [{"insert":"Test"},{"insert":"\n","attributes":{"header":1}}]
to stringify it :
JSON.stringify(goo)
'[{"insert":"Test"},{"insert":"\n","attributes":{"header":1}}]'
in this case your parse works like :
JSON.parse(foo)
0: {insert: 'Test'}
1: {insert: '\n', attributes: {…}}
length: 2
[[Prototype]]: Array(0)
Using ReactJS, how can I remove the double quotes from each array object without changing the array?
For example, given:
0: Array(2)
0: "23.94107556246209"
1: "54.00604248046876"
1: Array(2)
0: "24.457150524185852"
1: "55.09094238281251"
2: Array(2)
0: "23.90843786128921"
1: "55.18157958984375"
my desired output is:
0: Array(2)
0: 23.94107556246209
1: 54.00604248046876
1: Array(2)
0: 24.457150524185852
1: 55.09094238281251
2: Array(2)
0: 23.90843786128921
1: 55.18157958984375
What is the best way to achieve this?
const array = [["23.94107556246209", "54.00604248046876"], ["24.457150524185852","55.09094238281251"]]
const newArray = array.map(item => {
return item.map(val => Number(val))
})
use Number() to format your string value
Quill seems to present data output as deltas to build up the document incrementally. This is useful for Undo purpose or while the document is being edited. But after the document is saved, this deltas output is not helpful at all, has high overhead to store and hard to traverse the document structurally.
Example, the content of a single code block would be:
while (1) {
i++;
j++;
}
And the delta outputs
ops: Array(8)
0: {insert: "↵while (1) {"}
1: {attributes: {…}, insert: "↵"}
2: {insert: " i++;"}
3: {attributes: {…}, insert: "↵"}
4: {insert: " j++;"}
5: {attributes: {…}, insert: "↵"}
6: {insert: "}"}
7: {attributes: {…}, insert: "↵"}
length: 8
How do I flatten delta outputs to a simpler output that presents the document structurally. In this case, a single insert with "code block" attribute ?
You can use the Delta.compose method to flatten changes.
Here's an example from the documentation:
const a = new Delta().insert('abc');
const b = new Delta().retain(1).delete(1);
const composed = a.compose(b); // composed == new Delta().insert('ac');
There is another example of how to use this in the Autosave playground sample.
I don't get how Immutable JS List size will grown.
As in the example on official doc https://facebook.github.io/immutable-js/docs/#/List/push , pushing something in an immutable js List will automatically grown size.
In my code:
const list: List = List();
list.push(object);
console.log(list, list.size);
My output in consolle is:
(1) object
length: 1
___proto___: Array(0)
undefined
That is really different from the aspected output.
There is no size, if I use length in my code Typescript tell me that it doesn't exist "length" in List.
I use React with Typescript and Immutable.JS
Anybody has an idea of what happens?
Immutability means that operations do not change the original object but instead create a new one.
In your case the push method will return a new list with all the old elements and the new one you just added.
Your code should look something like this.
const list: List = List();
const newList = list.push(object);
console.log(list, list.size);
console.log(newlist, newlist.size);
This should print a size of 0 for the list variable and a size of 1 for the newList variable.
I am trying to create a firebase parent with multiple children. I looked into the documentation and I can't figure how to create many children in parallel level of my board child.
#unbind() if #unbind
#id = #uniqueId()
#dbRef = new Firebase url + "#{#id}"
#db = #$firebase #dbRef.child('board')
#db.$bind( #$scope, 'cells' ).then (unbind) =>
#unbind = unbind
This is my code so far.
tictactoe-lau
5e776bvj
board
0: value
3: value
4: value
5: value
6: value
7: value
This is the structure of my current db. I want 5e776bvj to have additional children, parallel to the board level.