我不明白下一行代码的 Javascript 解释:
var a = ["value"];
console.log(a[0]); // value
console.log(a[[0]]); // value
console.log(a[[[0]]]); // value
//...Run Code Online (Sandbox Code Playgroud)
为什么将数组视为值 0?
我试过deno -V,它只提供 deno 的版本,不包括 typescript 版本。
$deno -V
deno 1.0.0-rc2
$
Run Code Online (Sandbox Code Playgroud) 我有一个这样的数组:
var flightPlanCoordinates = [
{ lat: 37.772, lng: -122.214, status: "walking" },
{ lat: 36.772, lng: -123.214, status: "walking" },
{ lat: 21.291, lng: -157.821, status: "automotive" },
{ lat: -18.142, lng: 178.431, status: "automotive" },
{ lat: -27.467, lng: 153.027, status: "walking" },
{ lat: -26.467, lng: 151.027, status: "walking" },
];
Run Code Online (Sandbox Code Playgroud)
我希望将其拆分为三个数组,这些数组具有相同类型的对象,如下格式:
[{lat: 37.772, lng: -122.214, status: 'walking'},
{lat: 36.772, lng: -123.214, status: 'walking'}]
[{lat: 21.291, lng: -157.821, status: 'automotive'},
{lat: -18.142, lng: 178.431, status: 'automotive'}]
[{lat: …Run Code Online (Sandbox Code Playgroud) 我有一个列表,需要在单击列表上的任何项目时对其重新排序。字符串数组用于绑定。用于重新排序的函数正在返回正确的值。但是用户界面没有更新。
import React from 'react';
import ReactDOM from 'react-dom';
function swapElement(array, from, to) {
array.splice(to, 0, array.splice(from, 1)[0])
return array;
}
const List = props => {
let [list, setList] = React.useState(props.item)
const handleClick = index => {
const items = swapElement(list, index, 0);
console.log('UPDATED ARRAYS--------->', items)
setList(items);
}
return <ul> {
list.map((item, i) =>
<li style={{ margin: '25px' }}
onClick={() => handleClick(i)}
key={i}
>
{item}
</li>)
} </ul>
}
ReactDOM.render(
<List item={['A', 'B', 'C', 'D', 'E']} />,
document.getElementById('root')
);
Run Code Online (Sandbox Code Playgroud) 我是 reactjs 的新手,我试图获取 textarea 字符数,需要在用户输入 textarea 时显示,但无法获取计数也抛出状态对象是只读错误。我的代码是
import React from "react";
export default function FullWidthTabs() {
const [textAreaCount = 0, textAreaTotal = 250] = React.useState(0);
const recalculate = e => {
console.log("event value:", e);
textAreaCount = e.target.value.length;
};
return (
<textarea
type="text"
rows={5}
className="full_height_Width"
onChange={recalculate}
/>
);
}
Run Code Online (Sandbox Code Playgroud)