我正在尝试使用现有数组中的有限值创建一个新数组。下面的示例LargeArray包含许多属性 - 年份、书籍、gdp 和控制。假设我想创建一个仅包含年份和 GDP 的新数组。
var LargeArray = [
{year:1234, books:1200, gdp:1200, control:1200},
{year:1235, books:1201, gdp:1200, control:1200},
{year:1236, books:1202, gdp:1200, control:1200}
];
Run Code Online (Sandbox Code Playgroud)
我试图获取的新数组如下所示:
var NewArray = [
{year:1234, gdp:1200},
{year:1235, gdp:1200},
{year:1236, gdp:1200}
];
Run Code Online (Sandbox Code Playgroud) 我在jquery中尝试this.addclass将一个类添加到DIV,这可能是未知的.这可以用这种方式解决吗?
<style>.classOne { font-size:24px; color:#009900;}</style>
<script>
function hello()
{ alert();
$(this).addClass('classOne');
}
</script>
<div class="something" onclick="hello();"> Test information </div>
Run Code Online (Sandbox Code Playgroud)